You have learned quite a bit about macros but haven’t
yet learned how to execute them. This process varies depending on what
you’re trying to do. You can run a macro from the Macro Design window or
by double-clicking the macro in the Macros Group of the Navigation
Pane, triggered from a Form or Report event, triggered from a Data
Macro, or invoked by selecting a custom Ribbon button.
Running a Macro from the Macro Design Window
A macro can be executed easily from the Macro Design window. Running a
macro without groups is simple: Just click Run in the Tools group of the
Macro Tools Design tab. Each line of the macro is executed unless
conditions have been placed on specific macro actions. After you click
the Run button of mcrOpenCustomerList (shown in Figure 10.12), the Customer List form is opened.
From Macro Design view, you can
run only the first submacro in a macro. To run a macro with submacro,
click Run from the Tools group on the Macro Tools Design page to execute
the first group in the macro. As soon as the second submacro is
encountered, the macro execution terminates.
Running a Macro from the Macros Group of the Navigation Pane
To run a macro from the Macros group of the Navigation Pane, follow these two steps:
1. | Scroll
down to the Macros group in the Navigation Pane. If the Macros group
does not appear in the Navigation Pane, you will need to select All
Access Objects from the Navigation Pane drop-down and then expand the
Macros group.
|
2. | Double-click the name of the macro you want to execute, or right-click the macro and select Run.
|
If the macro you execute contains submacros, only the macro actions within the first group are executed.
|
Triggering a Macro from a Form or Report Event
Sometimes you are going to
execute a macro in response to an event on a form or report. Examples
are a form opening, someone clicking a command button, or a form
closing. Here, you learn how to associate a macro with a command button.
The form in Figure 2 illustrates how to associate a macro with the Click event of a form’s command button. Four steps are needed to associate a macro with a Form or Report event:
1. | Select the object you want to associate the event with. In the example, the cmdCheckGender command button is selected.
|
2. | Open the Property Sheet and click the Event tab.
|
3. | Click the event you want the macro to execute in response to. In the example, the Click event of the command button is selected.
|
4. | Use
the drop-down list to select the name of the macro you want to execute.
If the macro has submacros, make sure you select the correct submacro
subroutine. In the example, the macro mcrPersonalInfo and the macro name GetGender
have been selected. Notice the period between the name of the macro and
the name of the macro name submacro. The period is used to
differentiate the submacro (mcrPersonalInfo, in this case) from the macro name (GetGender, in this example).
|