Announcement

Collapse
No announcement yet.

Restrict Combobox Selection To List Only But Allow Deletion

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Restrict Combobox Selection To List Only But Allow Deletion

    I have the following code which works but after the user gets an initial error says that they have to enter what is a ComboBox choice they get a second error when they press backspace to delete their entry. Is there a way to just give them the first error but not an error when they press backspace to erase their mistake in the form?

    This checks the user input...
    Code:
    Private Sub Combobox5_Change()
        If ComboBox5.ListIndex < 0 Then
            MsgBox "Please Only Pick From The List.  Use Admin Page to Add More to the List", vbCritical, "Error"
        End If
    End Sub
    This is what is loaded as ComboBox choices. I only want them to pick what is on this list. Nothing else.
    Code:
        On Error Resume Next
        lngNRows = Range("Admin_Bikes").Rows.Count
        If lngNRows > 0 Then
            ComboBox5.RowSource = "Admin_Bikes"
        Else
            ComboBox5.RowSource = ""
            ComboBox5.AddItem "Empty"
        End If
    Thanks much,

    Guy

  • #2
    Re: Combobox Validation

    Code:
    Private Sub ComboBox1_Change()
        If ComboBox1 <> vbNullString And ComboBox1.ListIndex < 0 Then
        'CODE
        End If
    End Sub
    Last edited by Dave Hawley; February 14th, 2008, 16:54.

    Comment


    • #3
      Re: Combobox Validation

      Originally posted by Dave Hawley
      Code:
      Private Sub ComboBox1_Change()
          If ComboBox1 <> vbNullString And ComboBox1.ListIndex > 0 Then
          'CODE
          End If
      End Sub
      Dave, thank you for your reply - as always you are a big help...

      I tried that code but it seems to give an error ONLY when the user picks from the ListIndex (choices in the combobox drop down). User can freeform anything and no error.

      Guy

      Comment


      • #4
        Re: Restrict Combobox Selection To List Only But Allow Deletion

        It restricts users to choose from all but the 1st combobox item (listindex 0).

        Comment


        • #5
          Re: Restrict Combobox Selection To List Only But Allow Deletion

          Originally posted by Dave Hawley
          It restricts users to choose from all but the 1st combobox item (listindex 0).
          OK, I think I understand. How would I adjust this so the only valid entry is the choices in the combobox (I assume that is thelistiondex). Sorry if I sound confused. I am slow. It is late :-)

          Guy

          Comment


          • #6
            Re: Restrict Combobox Selection To List Only But Allow Deletion

            Code:
            Private Sub Combobox5_Change() 
                If ComboBox5.ListIndex < 0 Then 
                     MsgBox "Please Only Pick From The List.  Use Admin Page to Add More to the List", vbCritical, "Error" 
                End If 
            End Sub
            Try using your original code and set the MatchEntry property of combobox5 to MatchEntryComplete
            Bill
            Tip: To avoid chasing code always use Option Explicit.

            Comment


            • #7
              Re: Restrict Combobox Selection To List Only But Allow Deletion

              Hi,

              This is what is loaded as ComboBox choices. I only want them to pick what is on this list. Nothing else.
              Set the Style property to fmStyleDropDownList

              HTH
              Kris

              ExcelFox

              Comment


              • #8
                Re: Restrict Combobox Selection To List Only But Allow Deletion

                Originally posted by Krishnakumar
                Hi,



                Set the Style property to fmStyleDropDownList

                HTH
                Perfect, thank you. A simple solution that works great. Many thanks... Guy

                Comment


                • #9
                  Re: Restrict Combobox Selection To List Only But Allow Deletion

                  I thought you wanted to allow deletion of any choice?

                  Comment


                  • #10
                    Re: Restrict Combobox Selection To List Only But Allow Deletion

                    Originally posted by Dave Hawley
                    I thought you wanted to allow deletion of any choice?
                    Dave,
                    This solution seems to work. A user can type in a valid option and then change that option without any error. The user is forced to only user valid combobox options. I thought I tested it multiple times but will do again to make sure the user can delete their entry and change it.

                    Guy

                    Comment


                    • #11
                      Re: Restrict Combobox Selection To List Only But Allow Deletion

                      They can "change" their choice, but they cannot "delete" it once a choice has been made.

                      Comment

                      Working...
                      X