Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

combo box _Change error when user types a value excel 2010

$
0
0

I thought I had things working until one of my testers tried to type a value directly into my cbo box, it throws an invalid entry error and the debugger goes to this line of the change event;

Private Sub cboOrgName_Change()

     Me.txtOrgCode = cboOrgName.List(cboOrgName.ListIndex, 1)

 End Sub

 so I tried this code and it helps, no more combo box error but I still get the change event error

Private Sub cboOrgName_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
    Dim strTextEntered As String
    Dim lngIndex    As Long
    Dim blnValidEntry As Boolean

    strTextEntered = Me.cboOrgName.Text

    If Len(strTextEntered) = 0 Then Exit Sub

    'Assume that the entry is invalid unless we can prove otherwise
    blnValidEntry = False

    'Loop through each item in the combobox and see it any of those match
    'the text that has been entered
    For lngIndex = 0 To Me.cboOrgName.ListCount - 1
        If UCase$(strTextEntered) = UCase$(Me.cboOrgName.List(lngIndex)) Then
            blnValidEntry = True
            Exit For
        End If
    Next lngIndex

    If blnValidEntry = False Then
        Cancel = True
        Me.cboOrgName.SelStart = 0: Me.cboOrgName.SelLength = Len(Me.cboOrgName.Text)
        MsgBox Chr(34) & strTextEntered & Chr(34) & " is not a valid entry.  Please choose " & _
                "an entry from the drop-down box.", vbExclamation, "Invalid Entry"
    End If

one other thing to note is the same thing happened when I was using the properties set to match entries


Viewing all articles
Browse latest Browse all 11829

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>