Help!

Trapping "Invalid Property Value" errors

 
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> User Forms RSS
Next:  Word 2007 changes some letters for some reason  
Author Message
kMan
External


Since: Jun 01, 2006
Posts: 9



PostPosted: Sun Mar 18, 2007 8:29 pm    Post subject: Trapping "Invalid Property Value" errors
Archived from groups: microsoft>public>word>vba>userforms (more info?)

Hello all,

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
Back to top
Jay Freedman
External


Since: Mar 17, 2004
Posts: 3038



PostPosted: Mon Mar 19, 2007 3:09 am    Post subject: Re: Trapping "Invalid Property Value" errors [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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
End If
End Sub

Setting the Cancel parameter to True prevents the focus from going to
the next control on the form.

--
Regards,
Jay Freedman
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
wrote:

>Hello all,
>
>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
Back to top
kMan
External


Since: Jun 01, 2006
Posts: 9



PostPosted: Fri Mar 30, 2007 12:48 am    Post subject: Re: Trapping "Invalid Property Value" errors [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks

"Jay Freedman" wrote:

> 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
> End If
> End Sub
>
> Setting the Cancel parameter to True prevents the focus from going to
> the next control on the form.
>
> --
> Regards,
> Jay Freedman
> 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
> wrote:
>
> >Hello all,
> >
> >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
>
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> User Forms All times are: Eastern Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum