Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2004
    Posts
    67

    Question Unanswered: DoCmd.CancelEvent not working

    From the BeforeUpdate event of a combo-box, I am calling a public sub-routine that checks the validity of the selection based on other selections on the form. If the selection is bad, the public sub should show a msgbox and cancel the combo-box selection (return it to its previous selection).

    Well, the msgbox appears but the event doesn't cancel. Can anyone help?

    Here's the snippet:

    Code:
    'On bad combination, alert user and deny change
    BadCombo_Label:
    MsgBox ("You have selected an improper combination of Run Type and Vehicle Type" & vbCrLf & "(You can't have that car do that type of run)" & vbCrLf & "Your selection will be reset")
    DoCmd.CancelEvent
    Thanks,
    David

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    use Exit Sub ?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Jul 2004
    Posts
    67

    Thumbs down nope

    No, I don't want to cencel the sub, I want to cancel the event.

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    And the difference is?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    The BeforeUpdate event uses the Cancel variable. All you have to do is set Cancel = True and the event will be cancelled. Keep in mind that it is not like an exit, any code after Cancel=True will be executed. So you might actually need and Exit or and If to skip any code after the validity check.

  6. #6
    Join Date
    Jul 2004
    Posts
    67

    Thanks!

    Thank you for your help.

    For Teddy...the difference is that I wanted to cancel the updatingof the field to the value selected by the user. You were suggesting something that would just cancel the sub-routine that was triggered by the event.

Posting Permissions

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