Microsoft Office Tutorials and References
In Depth Information
You can copy an action, too, which can be useful after you’ve created an
action and entered all the appropriate arguments for it. To copy an action,
hold down the Ctrl key while you drag it to a new location. Access leaves the
action where it is and creates a copy where you tried to drag it.
Earlier versions of Access had a Comment column in the Macro window
where you could type descriptions and explanations to make the macro
more readable. In Access 2013, you add comments between actions, which
is the way that most programming languages work. To add a comment, drag
the Comment action from the Action Catalog to any location in your macro,
or choose Comment from the Add New Action drop-down menu and then
move the comment up to the spot where you want it. The first line of the
macro in Figure 1-2, earlier in this chapter, is a comment, shown as text
surrounded by /* and */ characters. (These characters may seem like odd
choices, but several programming languages use them to mark where
comments start and end.)
Adding comments to your macros is a great idea. Add a comment at the
beginning of the macro that says what the macro is supposed to do. If people
other than you use the Access database, also add your name and the date.
Creating subroutines in macros: Submacros
Programs, even macros, can get long and confusing. Programs also can get
repetitive; you may find yourself using the same series of actions in
different macros. Programmers the world over use subroutines to store a set
of actions (or commands) with a name. Instead of duplicating this set of
actions in all the places you want the actions to run, you call the subroutine
by using its name. Later, if you think of a better way to perform that series of
actions, you can change the subroutine, and all the programs that call it get
the new, improved version. Very efficient.
Starting in Access 2013, macros now have subroutines, called submacros. Put
any actions you want in a submacro (even another submacro!), and give the
submacro a name. When you run a macro, it does not run the actions inside
a submacro unless you specifically call the submacro by name.
To create a submacro in a macro, follow these steps:
1. Display the Action Catalog, if it’s not already displayed, by clicking
the Action Catalog button in the Show/Hide group on the Design tab
of the Ribbon.
2. If the Program Flow group of actions isn’t expanded (that is, doesn’t
have a list of actions below it), click the plus box to its left.
The Program Flow group is already expanded in Figure 1-2, earlier in this