Part IV: Professional Database Development
1052
FIGURE 30.3
The Hello World macro uses the MessageBox action to display a message.
Macro action
Message
Title bar caption
To run the macro, click the Run button in the Design ribbon’s Tools group. (The Run button looks
like a big red exclamation point at the far left of the ribbon.) When you create a new macro or
change an existing macro, you’ll be prompted to save the macro. In fact, you must save the macro
before Access runs it for you. When prompted, click yes to save it, provide a name such as
mcrHelloWorld, and click OK. The macro runs and displays a message box with the arguments
you specified (shown in Figure 30.4).
FIGURE 30.4
Running the Hello World macro displays a message box.
You can also run the macro from the Navigation Pane. Close the macro design window and display
the Macros group in the Navigation Pane. Double-click on the mcrHelloWorld macro to run it.
You’ll see the same message box that displayed when you ran the macro from the design window.
Notice that the message box always appears right in the middle of the screen, and blocks you from
working with Access until you click OK. These are built-in behaviors of the message box object,
and are identical in every regard to a message box displayed from VBA code.
When you’re satisfied with the Hello World macro, click on the close button in the upper-right
corner of the macro window to return to the main Access window.
Assigning a macro to an event
When you’re creating macros, you probably don’t want end users using the Navigation Pane to run
them — or worse, running them from the macro design window. Macros are intended for you to
automate your application without writing VBA code. In order to make an application easy to use,
assign your macros to an object’s event.