Results 1 to 8 of 8
  1. #1
    Star Lounger
    Join Date
    May 2001
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setting my own error (VBA - Word 97 SR2)

    Thanks for helping with my problem yesterday it now works a treat. I now have another slight problem (more of an annoyance really)

    In my form there is a combo box called txtPartner. On initialising the form I have it fill the combo box with the contents of a file and have the combo box set to only accept values that match the contents. If they type in something wrong they get a generic error (Invalid property value). I want to set my own message box for the error. I have had a look at help and the code I have is this

    Private Sub cmbPartner_change()
    On Error GoTo errorhandler
    Exit Sub
    errorhandler:
    MsgBox "Please enter a valid partner"
    End Sub

    but it is still bringing up the generic error. All help would be much appreciated

    Thanks in advance

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: setting my own error (VBA - Word 97 SR2)

    If you set the Style property of the combo box to 2 - fmStyleDropDownList instead of the default 0 - fmStyleDropDownCombo, the user will be forced to select an item from the list.

  3. #3
    Star Lounger
    Join Date
    May 2001
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: setting my own error (VBA - Word 97 SR2)

    thanks again that worked perfectly. As a point of interest - is there a way to get your own message box in this situation or is the fix you gave me the only solution?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: setting my own error (VBA - Word 97 SR2)

    The error you describe in the first post in this thread is not caused by the combo box as far as I can tell. If the Style property is set to 0, the combo box will accept anything typed in the text box part. The "Invalid property error" arises when you try to do something with the value of the combo box; this is in another procedure or function, not in the OnChange event of the combo box. You can set up error handling in that procedure or function to display your own error message and to redirect the user to the combo box by using cmbPartner.SetFocus.

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: setting my own error (VBA - Word 97 SR2)

    Hi Hans,
    If you set the MatchRequired property to true then you will get the "Invalid Property Value" error message described if you type something that's not in the list. To avoid that message, I would set MatchRequired to False and then test for MatchFound in the BeforeUpdate event - if not found, set Cancel = True.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: setting my own error (VBA - Word 97 SR2)

    Thanks Rory,

    Somehow the MatchRequired property of MSForms combo boxes has escaped my attention, although I know and use the LimitToList property of Access combo boxes. <img src=/S/doh.gif border=0 alt=doh width=15 height=15>

  7. #7
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: setting my own error (VBA - Word 97 SR2)

    That's the joy of all these sets of controls that look alike but have totally different properties/methods/events! Where's the NotInList event when you need it?? <img src=/S/smile.gif border=0 alt=smile width=15 height=15>
    Regards,
    Rory

    Microsoft MVP - Excel

  8. #8
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: setting my own error (VBA - Word 97 SR2)

    In addition to what others have said, you need a Resume statement at the end of your errorhandler routine to get you out of error mode.
    Legare Coleman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •