Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 15: Using Access Data Macros


557


Using the Action Catalog


The Action Catalog on the right side of the Macro Designer serves as the repository of macro
actions you add to your data macros. The contents of the Action Catalog depend entirely on which
table event has been selected, so its appearance varies considerably while you work with Access
macros.


Program flow


At the top of the Action Catalog are certain program-flow constructs you apply to your macros.
When working with data macros, the only program-flow constructs available are comments,
groups, and If blocks. Comments help document your macros and should be used if the macro’s
logic is not easily understood.


A macro group provides a way to wrap a number of macro actions as a named entity. The group can
be independently collapsed (you’ll see collapsed macro sections in the “Adding macro items” sec-
tion, later in this chapter), copied, and moved around within a macro. A macro group is not, how-
ever, an executable unit. Instead, it’s simply meant to provide a convenient way to establish a block
of macro actions to simplify your view of the macro in the Macro Designer.


The If block adds branching logic to a macro. You’ve seen several examples of the VBA If...
Then...Else construct in other chapters, and a macro If is no different. Double-click or drag
the If onto the macro’s design surface (see Figure 15.4) to define a block of macro actions that are
executed only when the condition specified in the text box at the top of the If block is true.


In Figure 15.4, the body of the If block executes only when the Cost field is set to a value less
than zero. There are many other ways to handle this situation, including using a validation rule,
but an If block attached to the Product table’s AfterUpdate event is automatic and requires no
effort on the part of the user.


In the lower-right corner of the If block are options to add an Else or an Else If to the If
block. Use these options to extend the If block to include other conditions you want to check as
part of the same If block.


Data blocks


The Data Blocks group of macro actions (except for Lookup Record) is only available for “after”
events. As you’ll read in the “Data actions” section, later in this chapter, the “before” events are
meant to be very fast and lightweight, so they don’t provide for CPU-intensive operations such as
adding or editing new records.


Each of the data-block constructs includes an area for adding one or more macro actions. The data
block performs all the macro actions as part of its operation. In other words, you set up the data
block you want to perform (for example, EditRecord), and then add the actions you want to
execute as part of the block.

Free download pdf