Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    List boxes / VBA (Word 2003)

    I'm working with a custom user form where I display three list boxes. The three list boxes are for To, CC and BCC. The first list box is filled with the names a user selects from a database. The user may then choose to move some of the names to the CC or BCC list box. This functions as expected. There are three additional list boxes which contain the corresponding ID for each name. As the user relocates the names in the To CC and BCC list boxes, the corresponding ID numbers move withint the related three list boxes. All of this functions as expected.

    The 3 list boxes which hold the IDs are not visible to the user. They are below the bottom border of the user form. I learned early on that I had better luck if I added Me.Repaint each time my code "moved" a name and its corresponding ID. In testing my code, the IDs always mimic the names as expected. I was happy for several months. Yesterday -- for the first time -- my code had trouble reading from the "hidden" list boxes. The code had no trouble retrieving .Count for each list box, but sometimes the code returned nothing for the values of the list box items. If I made opened the heith of the user form so that the list boxes were not hidden, I had no trouble.

    What I've done is pretty simple: the event code for the command button that closes the user form adjusts the height before hiding the form:

    Me.Height = Me.Height + 40
    Me.Hide

    This works well for me... about 95% of the time. Every once in a while one or two boxes is ignored (never all three). Most of the time, but not always, all values are retrieved; rarely, one of three values in a list box is left off.

    Am I not following the best method for setting and retrieving values from hidden controls? I'm still using Me.Repaint, an event I had never previously found a use for. All values are being placed into the proper list boxes; the .Count is correct; once in a great while, an empty strings are returned for the values of a list box.

    Thanks,
    Richard Barrett

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: List boxes / VBA (Word 2003)

    Instead of using separate list boxes for names and IDs, I'd use list boxes with two columns, of which one is hidden by setting the ColumnWidths property to (for example) 72;0. The visible column contains the names, and the hidden column the corresponding IDs.
    You can use the List property of the list box to populate columns - look this keyword up in the help and view the example.

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: List boxes / VBA (Word 2003)

    Thanks. Do hidden columns pose any danger similar to what I've experienced with hidden list boxes? If the hidden attribute was the reason for my trouble, I'm wondering if it would occur with hidden columns. Have you had good luck with this?

    Thanks,
    Richard

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: List boxes / VBA (Word 2003)

    I've never experienced problems with hidden columns in list boxes and combo boxes, and I've used them quite often, so I think you're safe! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

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