Limiting choice to the options on combobox


J

Johanna Gronlund

Hello,

On my userform, I have a combobox that I have set up for my 49 items. The
code looks like this:

Private Sub ComboBox1_Change()
ActiveDocument.FormFields("Text1").Result = ComboBox1.Value
End Sub

Private Sub Cmdclose_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
ComboBox1.ColumnCount = 1
'Load data into ComboBox
ComboBox1.List() = Array("Option1", "Option2", "Option3", ..."Option49")
End Sub

At the moment, the users can select any of the options I have provided in my
combobox or type their own option. How can I limit their choice just to those
on the combobox? I have

Many thanks in advance,

Johanna
 
Ad

Advertisements

J

Jay Freedman

Add this line to the UserForm_Initialize procedure:

ComboBox1.MatchRequired = True

Equivalently, in the userform designer view in the VBA editor, click on the
combobox, go to the Properties pane (press F4 if it isn't visible), and set
the MatchRequired property to True there; then you don't need the line of
code.

According to the help topic on the MatchRequired property, "The user can
enter non-matching values, but may not leave the control until a matching
value is entered."

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Combo box 8
ComboBox Help 1
User Form issue 5
Macro for combo/drop down list 12
User From Combo box help 1
ComboBox with VBA 0
Populate combobox 6
populating the dropdowns in a combobox when opening the doc 1

Top