Microsoft Access VBA Programming for the Absolute Beginner
Cancels a cancelable event (an event that has a Cancel parameter).
Syntax
DoCmd.CancelEvent()
Example
The following example displays a dialog asking the user whether he or she wants to save changes to a record. If the user clicks the No button, then the CancelEvent method is called to cancel the update.
Private Sub Form_BeforeUpdate(Cancel As Integer) If MsgBox("Are you sure you want to save changes to this record?", _ vbYesNo Or vbInformation, "Confirm Upate") = vbNo Then DoCmd.CancelEvent End If End Sub
Comments
-
The CancelEvent method can only be called inside an event procedure.
-
Calling the CancelEvent method is equivalent to setting an event handler’s Cancel parameter to True.
-
If an event is not cancelable (has no Cancel parameter), calls to the CancelEvent method have no effect.
Категории