Consulting

Results 1 to 9 of 9

Thread: Solved: Restrict combo box selection to items in list

  1. #1
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location

    Solved: Restrict combo box selection to items in list

    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?

  2. #2
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Can you attach the template?

  3. #3
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    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.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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.....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I also think you should be using

    [VBA]
    Private Sub Document_New()
    End Sub
    [/VBA]
    In the thisdocument module instead of AutoNew unless you have an old version of Word.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    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.

  7. #7
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    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?

  8. #8
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    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.

  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Thanks for posting your solution Clhare, I did not know that.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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