Consulting

Results 1 to 2 of 2

Thread: how to populate textbox based on combobox selection in word

  1. #1

    how to populate textbox based on combobox selection in word

    Hi,

    I want to populate textbox (activex) in word based on combobox(activex) selection - filled from excel. I have a column named Koda2 in excel file named "popravila" in worksheet basisdaten, and a want when i choose a value in combobox to fill a textbox with the value from the same worksheet in column "nanosi".
    ex.
    koda2 nanosi

    12312 45m
    78429 94m
    ...
    When I choose 12312 in combobox i want to fill automatically textbox with value 45m.

    I fill combobox with that code:

    Public Sub UserForm_Initialize()

    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim NoOfRecords As Long

    Set db = OpenDatabase("C:\Users\Ivan_Andriana\Documents\Iskra ISD\popravila\popravila.xls", False, False, "Excel 8.0;")
    Set rs = db.OpenRecordset("SELECT * FROM Koda2")
    With rs
    .MoveLast
    NoOfRecords = .RecordCount
    .MoveFirst
    End With

    ComboBox1.ColumnCount = rs.Fields.Count

    ComboBox1.Column = rs.GetRows(NoOfRecords)

    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing
    End Sub

    Thanks for help

  2. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    Cross-posted at: http://www.msofficeforums.com/word-v...tion-word.html
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

    Also, when posting code, please use the VBA tags. They're on the menu.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •