A submacro, as the name implies, is a macro within another macro. You can create a macro that contains multiple submacros, as a method of organizing similar macros under a single macro object in the Navigation Pane. For example, if you are creating several macros that are primarily concerned with opening and printing reports, you might want to create them as submacros within a macro object named “ReportSubmacros.” Submacros are also suitable for use as “subroutines” within a macro, such as for error handling.
For more introductory information about creating macros, see the article Create a user interface (UI) macro.
In the video
Create a submacro
You add a Submacro block to a macro in the same way that you a macro action.
- Open the macro in Design view:
- For standalone macros, right-click the macro in the Navigation Pane, and then click Design View.
- For embedded macros, click the words [Embedded Macro] in the property sheet, and then click the Build button
.
- In the Macro Builder, select Submacro from the Add New Action drop-down list, or drag a new Submacro block from the Action Catalog into the macro pane.
- Drag macro actions into the submacro block, or select actions from the Add New Action list that appears within the block.
Notes
- You can also create a Submacro block by selecting one or more actions that you have already added to the macro pane, right-clicking them, and then selecting Make Submacro Block.
- Submacros must either be the last blocks or the only blocks in a macro. You cannot add any actions (except more submacros) below a submacro.
- If you run a macro that only contains submacros without specifically naming the submacro you want, only the first submacro will run.
- You cannot nest submacros within other submacros.
Top of Page
Run a submacro
A submacro is usually called by name from an event property or from the RunMacro or OnError macro actions. In most cases, you can select the submacro from a drop-down list, and they are displayed in the following syntax:
macroname.submacroname
For example, suppose that you have a submacro named OpenAssetList, which is contained in a macro object named ReportSubmacros. To run this submacro when a button is clicked, you would select ReportSubmacros.OpenAssetList from the drop-down list in the button’s On Click event property box.
Top of Page
Add an error-handling submacro to a macro
Submacros work well as subroutines within a macro. When used in this way, you call the submacro from elsewhere in the macro by using the RunMacro or OnError macro actions. This section shows you how to add a simple error-handling submacro to a macro. We recommend adding an error handling submacro to each macro as you write it, and leaving it in the macro permanently. When you use this method, Access displays descriptions of errors as they occur, helping you correct problems more quickly.
Use the following procedure to add an error-handling submacro to a macro:
- Open the macro in Design view.
- At the bottom of the macro, select Submacro from the Add New Action drop-down list.
- In the box just to the right of the word Submacro, type a name for the submacro, such as ErrorHandler.
- From the Add New Action drop-down list that appears within the Submacro block, select the MessageBox macro action.
- In the Message box, type the following text: =[MacroError].[Description]
- At the bottom of the macro, select OnError from the Add New Action drop-down list.
- Set the Go to argument to Macro Name.
- In the Macro Name box, type the name of your error-handling submacro (in this example, ErrorHandler).
- Drag the OnError macro action to the very top of the macro.
The following illustration shows a macro with the OnError action and a Submacro that is named ErrorHandler.

The
OnError macro action is placed at the top of the macro, and calls the
ErrorHandler submacro in the event of an error.

The
ErrorHandler submacro only runs if it is called by the
OnError action, and displays a message box that describes the error.
Top of Page