RunMacro Action

Description

You can use the RunMacro action to run a macro. The macro can be in a macro group.

You can use this action to:

  • Run a macro from within another macro.
  • Run a macro based on a certain condition.
  • Attach a macro to a custom menu command.

Setting

The RunMacro action uses the following arguments.

Action argument

Description

Macro Name

The name of the macro to run. The Macro Name box in the Action Arguments section of the Macro window shows all macros (and macro groups) in the current database. If the macro is in a macro group, it is listed under the macro group name in the list as macrogroupname.macroname. This is a required argument.

If you run a macro containing the RunMacro action in a library database, Microsoft Access looks for the macro with this name in the library database and doesn’t look for it in the current database.

Repeat Count

The maximum number of times the macro will run. If you leave this argument blank (and the Repeat Expression argument is also blank), the macro runs once.

Repeat Expression

An expression that evaluates to True (-1) or False (0). The macro stops running if the expression evaluates to False. The expression is evaluated each time the macro runs.


Remarks

If you enter a macro group name for the Macro Name argument, Microsoft Access runs the first macro in the macro group.

This action is similar to clicking Macro on the Tools menu, which runs a specified macro. However, the command runs the macro only once, whereas the RunMacro action can run a macro as many times as you want.

Tip You can use the Repeat Count and Repeat Expression arguments to determine how many times the macro runs:

  • If you leave both arguments blank, the macro runs once.
  • If you enter a number for Repeat Count but leave Repeat Expression blank, the macro runs the specified number of times.
  • If you leave Repeat Count blank but enter an expression for Repeat Expression, the macro runs until the expression evaluates to False.
  • If you enter values for both arguments, the macro runs the number of times specified in Repeat Count or until Repeat Expression evaluates to False, whichever occurs first.

When you run the original macro, and it reaches the RunMacro action, Microsoft Access runs the called macro. When the called macro has finished, Microsoft Access returns to the original macro and performs the next action.

Note Notes

  • You can call a macro in the same macro group or in another macro group.
  • You can nest macros. That is, you can run macro A, which in turn calls macro B, and so on. In each case, when the called macro has finished, Microsoft Access returns to the macro that called it and runs the next action in that macro.

To run the RunMacro action in Visual Basic, use the RunMacro method of the DoCmd object.

See Also

RunMacro Method.