Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    San Francisco, California, USA
    Posts
    358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Listbox (or combobox) with 2 columns in Word 2003

    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...

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    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.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    San Francisco, California, USA
    Posts
    358
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jscher2000 View Post
    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.
    Last edited by Cecilia; 2011-02-16 at 14:12.

Posting Permissions

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