HandsOn Writing the Form CommandBefore Execute Event Procedure

1. In the Visual Basic Editor window, double-click Form_Sales Analysis Subform 1.

2. The Code window shows several event procedures you prepared earlier in this chapter. Enter the following Form_CommandBeforeExecute event procedure below the last procedure code.

Private Sub Form_CommandBeforeExecute(ByVal Command As _ Variant, ByVal Cancel As Object)

If Command = OWC11.plCommandAutoFilter Then MsgBox "Auto filtering is not allowed." Cancel.Value = True End If End Sub

3. To test the above event procedure, open Sales Analysis Subform 1 in Form view. Because you've already created several event procedures for this form, various events will be triggered. Respond appropriately to the

Part IV

prompts. Once the form is opened, right-click anywhere in the PivotTable and choose the AutoFilter command from the shortcut menu. The Form_ CommandBeforeExecute event procedure will fire and you will see the message informing you that this command is disallowed.

0 0

Post a comment