Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

The Submacro statement in Access defines a separate macro in the Macro Designer window.

Setting

The Submacro action has only one required argument.

Action argument

Description

Name

A string that appears as the name of the macro.

Remarks

You can use the Submacro statement to define separate sets of actions. You can run the actions defined in submacros from another macro using the RunMacro action. In the Macro Name argument of the RunMacro action, use the following syntax to run the submacro:

<macro name>.<submacro name>

You can also use the Submacro statement to define an error handling set of actions within a macro.

Example

The following macro demonstrates the use of the Submacro statement along with a OnError macro action. In this example, the OnError action specifies that Access run a custom error handling submacro named ErrorHandler when an error occurs. If an error occurs in any of the actions that follow, Access jumps to the ErrorHandler submacro. The ErrorHandler submacro displays a message box that refers to the MacroError object to display information about the error.

Here is a screenshot of the Access macro designer (Access version 2010 and higher) with the previous example. In this case, the expression in the SetLocalVar action triggers an error because it is trying to divide a number by zero. Access moves down to the submacro named ErrorHandler and displays the error information in a message box.

Access macro design surface displaying an OnError macro action.

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×