In a Word VBA userform, we have set the combo box (cbo) to require a match as we don’t want the user to select anything other than what is in the list. However, we do want them to be able to type to be able to quickly find the entry in the list. Unfortunately, if they type something that doesn’t match, they get the Microsoft ‘Invalid Property Value’ error. We would like them to get a more meaningful error message, such as ‘Please select an entry from the list.” We have tried trapping the error to no avail, and have tried using the Exit event when exiting the combo box to see if the value matches something in the list. This works, and will bring up the message box we want, but then it won’t set the focus and select the text in the combo box afterwards. The code we are using is:
Sub cbo_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If cbo.MatchFound = False Then
MsgBox “blah blah”
cbo.SetFocus
With cbo
.SelStart = 0
.SelLength = Len(.Value)
End With
End If
End Sub