You can use the StopMacro macro action in Access desktop databases to stop the currently running macro.
Setting
The StopMacro action doesn't have any arguments.
Remarks
You typically use this action when a condition makes it necessary to stop the macro. You can use a conditional expression in the macro's action row that contains this action. When the expression evaluates to True (–1), Access stops the macro.
For example, you might create a macro that opens a form showing the daily order totals for the date entered in a custom dialog box. You could use a conditional expression to be sure that the Order Date control on the dialog box contains a valid date. If it doesn't, the MessageBox action can display an error message and the StopMacro action can stop the macro.
If the macro has used the Echo or SetWarnings actions to turn echo or the display of system messages off, the StopMacro macro action automatically turns them back on.
This action isn't available in a Visual Basic for Applications (VBA) module.
Example
Synchronize forms by using a macro
The following macro opens a Product List form in the lower-right corner of the Suppliers form, displaying the current supplier's products. It shows the use of the Echo, MessageBox, GoToControl, StopMacro, OpenForm, and MoveAndSizeWindow macros actions. It also shows the use of a conditional expression with the MessageBox, GoToControl, and StopMacro actions. This macro should be attached to the Review Products button on the Suppliers form.
Condition | Action | Arguments: Setting | Comment |
Echo | Echo On: No | Stop screen updating while the macro is running. | |
IsNull([SupplierID]) | MessageBox | Message: Move to the supplier record whose products you want to see, then click the Review Products button again. Beep: Yes Type: None Title: Select a Supplier | If there is no current supplier on the Suppliers form, display a message. |
... | GoToControl | Control Name: CompanyName | Move focus to the CompanyName control. |
... | StopMacro | Stop the macro. | |
OpenForm | Form Name: Product List View: Datasheet Filter Name: Where Condition: [SupplierID] = [Forms]![Suppliers]![SupplierID] Data Mode: Read Only Window Mode: Normal | Open the Product List form and show the current supplier's products. | |
MoveAndSizeWindow | Right: 0.7799" Down: 1.8" | Position the Product List form in the lower right of the Suppliers form. |
No comments:
Post a Comment