The error occurs because the default value of the combobox's
..ListIndex property is -1.
The simplest fix is to set the .ListIndex value of each combobox to 0
in the UserForm_Initialize routine. That makes the first item in the
list be the default value, and there is no way for the user to force
the .ListIndex back to -1.
If for some reason you don't want any of the items in the box to be
the default but you still want to catch the condition before it causes
the error, create combobox_Exit procedure for each combobox and check
the .ListIndex value:
Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If ComboBox1.ListIndex < 0 Then
MsgBox "You must select an item in ComboBox1"
Cancel = True
Setting the Cancel parameter to True prevents the focus from going to
the next control on the form.
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
On Sun, 18 Mar 2007 16:29:00 -0700, kMan
>I have a form with comboxes, whose selections are restricted to only the
>values in these (MatchRequired = True)...
>Problem though, when user clicks on one of these comboboxes and exits
>without selecting an entry, word spits-out a "Invalid Property Value" error
>message. Is it possible to trap this error and define my own error handling
>procedure, and if so, where would I do this? In the function that initialises
>the form, or in the form_initialize routine?
>Thanks for your help