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