Create a Macro Group - MS-Access Tutorial
Create a Macro Group
If you create several macros that apply to controls on the same form or report, you can group them together as one file. Using macro groups offers two advantages:
- It reduces the number of macro names in the Navigation Pane.
- You can find all the macros for a single form or report in one place, where they're easy to edit, if necessary.
To create a macro group, open the macro sheet as usual and in the Show/Hide group, click the Macro Names command to display the Macro Name column. Add a macro to the sheet and enter a name for it in the Macro Name column of the first row of the macro. Add the rest of the actions to the macro.
To add another macro, enter the name in the Macro Name column and add the actions that you want to occur.
When Access runs a macro in a group, it begins with the action in the row that contains the macro name and continues until it finds no more actions or encounters another macro name. After adding all the macros to the group, close and save it as usual with the group name.
TIP: The macros in a group are much easier to read if you leave at least one blank row between the macros. You can also leave several rows blank at the top of the macro and add information in the Comment column that explains the purpose of the macro and where it's called from. Then the macro starts on the next row, where the Name and first Action appear.
When you assign macros from a group to an event property, you need to use the group name as well as the macro name. In the Property Sheet for a control, the drop-down list in an event property shows compound names for all of the macros in a group, as well as the names of all of the single macros. The group name and the macro name both appear separated by a period: macrogroupname.macroname.
Assigning AutoKeys
You can create a special macro group named AutoKeys, in which you can assign an action or a set of actions to a specific key or key combination. These act like the shortcut key combinations that you can use to carry out a ribbon command. Pressing the key or combination of keys carries out the action that you specify. You can add as many individual macros to the group as you need, each one named with the key or key combination that runs it.
CAUTION: If you use a key combination that Access already uses, such as ctrl-c for Copy, your actions will replace the Access key assignment. Also be warned that resetting to default assignments will remove all custom assignments.
Table-5 shows a list of valid AutoKeys key combinations. These combinations are part of the set that can be used by the Visual Basic SendKeys statement. The SendKey syntax form is used as the macro name. The carat symbol (^) represents ctrl and the plus sign (+) represents shift. Function keys and other key names are enclosed in curly brackets ({}).
TABLE-5 AutoKeys Key Combinations
Key CombinationMacro NameCTRL-Any letter or number key^A, ^4Any function key{F1}CTRL-Any function key^{F1}SHIFT-Any function key+{F1}INS{INSERT}CTRL-INS^{INSERT}SHIFT-INS+{INSERT}DEL{DELETE} or {DEL}CTRL-DEL^{DELETE} or ^{DEL}SHIFT-DEL+{DELETE} or +{DEL}