Re: How do I add items to a comboBox in Word 2003 userForm?

  • Thread starter Thread starter Jay Freedman
  • Start date Start date
J

Jay Freedman

Hi duBedat,

To allow multiple selections in the list, you must use a listbox
control instead of a combobox.

The initialization of the listbox will be exactly like the one you
have for the combobox. In the Properties pane for the listbox, change
the value of the MultiSelect property to fmMultiSelectExtended -- or
you can do this in code by including this line inside the With group
in the Userform_Initialize procedure:

.MultiSelect = fmMultiSelectExtended

This will also change the way you "read" the selected items when the
user clicks the OK button. When you have a single-selection listbox or
a combobox, you would read the selected item from the .Value property
or get its index from the .ListIndex property, but that doesn't work
when multiple selection is allowed. Instead, you need to loop through
all the indexes and note which ones are indicated by .Selected(index)
= True. See the example in the VBA help for the Selected property.
 
Wow,
thanks heaps Jay,
your explanation of multiple selections is very thorough & easy enough for
a novice like me to get my head around.

I probably should apologise for not being very concise in posting my
questions, because what I really should have asked was:

How can I present a list to the user, but still allow the user to manually
enter in information if the list does not suit them?

Many kind regards
duBedat
 
Hi duBedat,

Your requirements are hard to meet, to have both multiple simultaneous
selections and entry of items that aren't yet in the list. The
standard listbox allows multiple selection but has no way to enter new
items, while the standard combobox allows new items but not multiple
selections.

The solution requires replacing the combobox with two separate
controls -- a listbox and a textbox -- plus a command button. The idea
is that the user can type a new item in the textbox if necessary, and
click the button to add the new item to the list in the listbox. Then
the user can make multiple selections in the listbox as needed.

To make the pair act more like a combo box, you can use the textbox's
Change event to move the selection in the listbox to the nearest
matching item as the user types in the textbox.

I'd say this was more of an intermediate-level project, certainly not
novice-level. If you want to learn more about it, read the VBA help
topics on the ComboBox and ListBox objects and their properties and
methods, especially .AddItem, .List, .ListIndex, and .ListCount.
 
Hi again Jay,
man, you know your stuff, that is tops & again, easy enough for me to
understand.

Perfect for what I would like to acheive, as I want to change an "AutoNew
Macro" that has about 20 or so pop-ups that ask for input, into an Entry Form.

I was initially proud of my Macro, but after a few times through it, I
became very tired of the incessant pop-ups, so I think an entry type form
would alleviate that.

Another advantage of this type of entry form would be to eliminate having to
continually retype "regular expressions" for want of a better term.

Thank you so very much Jay
duBedat
 
Back
Top