PDA

View Full Version : Solved: Restrict combo box selection to items in list



clhare
07-17-2007, 01:50 PM
I have a combo box that I need to set up so that the user can only select an item from the list--they can't add their own item to the list and they can't change any item in the list. How do I do that?

I tried changing the Match Required property to True, but find that when I run the template, I can select one of the options and then change it to whatever I want.

Is there a way to ensure that can't happen?

geekgirlau
07-17-2007, 08:46 PM
Can you attach the template?

clhare
07-18-2007, 05:13 AM
Here's a sample template. In it I have 2 combo boxes on a userform and one combo box in the document table. In my actual template, there are about 5 combo boxes on the userform (the main ones) and all the other combo boxes are in the table itself (there were too many options for a dropdown box, and the user wanted to be able to go back and make changes to the selections if needed.

I copied both combo boxes on the userform from my actual template.

The Action combobox will let me make a matching selection, then add to it (or even backspace up to the first letter and type something else entirely for the rest of the entry).
The Location combo box will not let me out of it until the selection matches.
The Dept combo box is in the table. That one will also let me add to the selection or delete part of it and type something else.All three combo boxes have the same properties, but they are not all acting the same.

lucas
07-18-2007, 06:04 AM
I don't know about the one on the page but the two on the userform have different properties. The Matchrequired property is set to false on the cboaction combo and true on the cbolocation combobox.....

lucas
07-18-2007, 06:09 AM
I also think you should be using


Private Sub Document_New()
End Sub

In the thisdocument module instead of AutoNew unless you have an old version of Word.

clhare
07-18-2007, 06:12 AM
You're right about the one on the form. But I just double-checked the one in the document, and the MatchRequired property on that combobox is set to True, but it does let me add to a selection.

clhare
07-18-2007, 07:18 AM
Would there be a way to check the value of the control embedded in the document when the focus leaves the control to make sure it matches somthing in the list? Maybe, return focus to the control and give an error message like it would do when the control is on a userform?

clhare
07-18-2007, 07:59 AM
Found a solution...

If the combo box is embedded in the document itself, I have to also change the Style property to fmStyleDropDownList. Once I've done that, the user can't alter their selection in any way.

lucas
07-18-2007, 08:44 AM
Thanks for posting your solution Clhare, I did not know that.