Part IV: Professional Database Development
1054
Tip
You aren’t limited to the button’s Click event. If you want a macro to run every time a form loads, set the On
Load event property of the form to the macro’s name. Select the Event tab on any object’s Property Sheet to
see the available events.
Note
Historically, there has been quite a bit of confusion about the names of events and their associated event prop-
erties. An event is always an action, such as Click, while its event property is OnClick or On Click.
Conceptually, they’re almost the same thing, but in technical terms, an event (like Click or Open) is an action
supported by an Access object (like a form or command button), and an event procedure (OnClick or
OnOpen) is how the event is attached or bound to the object.
Multi-Action Macros
The true power of macros comes from performing multiple actions at the click of a button.
Creating a macro that runs a series of action queries is better than double-clicking each action
query in the Navigation Pane — you might forget to run one or you may run them out of proper
sequence.
For this next example, the Chapter30.accdb contains two delete queries that remove data from
two different tables — tblContacts_Backup and tblProducts_Backup. Chapter30.
accdb also includes two append queries that copy records from tblContacts and tbl
Products to the backup tables. Table 30.1 shows the macro actions and action arguments for
mcrBackupContactsAndProducts (a portion of which is shown in Figure 30.6).
Note
If all the actions don’t appear in the Action drop-down list, click on the Show All Actions command in the
Show/Hide group of the macro’s Design ribbon. Some macro actions require a trusted database or enabling
macros through your security settings. Also, some macro actions are considered unsafe because they modify
data in the database or perform actions that may cause damage to the application if used incorrectly. Macro
actions that are considered unsafe are indicated by a warning icon (which looks like an inverted yellow triangle
containing an exclamation point) in the macro designer. By default, Access only displays trusted macro actions
that run regardless of the security settings.
TABLE 30.1
mcrBackupContactsAndProducts
Action Action Argument Action Argument Setting
Hourglass Hourglass On Yes
SetWarnings Warnings On No