• Listbox (or combobox) with 2 columns in Word 2003

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Listbox (or combobox) with 2 columns in Word 2003

    Author
    Topic
    #474837

    Hi,

    Can anyone point me to a primer or tutorial for using listboxes with 2 columns? I’m having a brain dead moment and can’t figure it out, it’s not the same in Word as it is in Access.

    So I have an Access table (tblAgencies) with two columns, Agency and AgencyID. I’d like to have Agency appear in the Word textbox with AgencyID hidden. Then when an agency is chosen, I want to know the Agency ID that was chosen so I can look it up in the Access table and display it in Word.

    I can find examples of how to load an array (which seems overly complicated for what I want to do), but there’s nothing about how to get the value (the ID) back out of the Word box…

    Viewing 0 reply threads
    Author
    Replies
    • #1267814

      Is this a control in the body of the document or in a UserForm? You have multiple choices for each, so let us know what you’ve tried.

      • #1267912

        Is this a control in the body of the document or in a UserForm? You have multiple choices for each, so let us know what you’ve tried.

        A Form control. I figured it out, actually 😉 (but I have another question ready)

        If I set the combo box to 2 columns, then when adding stuff to it, the first column refers to the list itself, the 2nd column refers to the column of the combo box you want to add it to.

        So my code looks roughly like this:

        Do Until rst.EOF
        cboAgencies.AddItem
        cboAgencies.List(i, 0) = rst!Agency
        cboAgencies.List(i, 1) = rst!ID
        i = i + 1
        rst.MoveNext
        Loop

        (I know the ID usually comes first, but it displays a bit prettier this way.)

        Then I can pick up the ID by using cboBox.value and looking it up in Access. Whew.

    Viewing 0 reply threads
    Reply To: Listbox (or combobox) with 2 columns in Word 2003

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: