Form.CommandBeforeExecute event (Access)
Occurs before a specified command is executed. Use this event when you want to impose certain restrictions before a particular command is executed.
expression.CommandBeforeExecute (Command, Cancel)
expression A variable that represents a Form object.
|Command||Required||Variant||The command that is going to be executed.|
|Cancel||Required||Object||Set the Value property of this object to True to cancel the command.|
The OCCommandId, ChartCommandIdEnum, and PivotCommandId constants contain lists of the supported commands for each of the Microsoft Office web components.
The following example demonstrates the syntax for a subroutine that traps the CommandBeforeExecute event.
Private Sub Form_CommandBeforeExecute( _ ByVal Command As Variant, ByVal Cancel As Object) Dim intResponse As Integer Dim strPrompt As String strPrompt = "Cancel the command?" intResponse = MsgBox(strPrompt, vbYesNo) If intResponse = vbYes Then Cancel.Value = True Else Cancel.Value = False End If End Sub
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.