Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 15: Using Access Data Macros .......................................................................................


553


There are many different ways to use data macros in Access 2010, including the following:

l Verifying that a customer’s payments are up to date before allowing additional charges to
be made
l Automatically calculating shipping costs or sales taxes as part of a sales table

l (^) Ensuring that a field’s value falls within required limits before the record is updated in the
database
l (^) Keeping a log of changes to a products table
Although these same rules are easily applied at the application level, the logic enforcing these rules
must be repeated every time the data is used by the application. Having these relatively simple
actions implemented at the data level means that the user interface logic (VBA code and macros)
can focus on more complex operations.
Looking at How Data Macros Are Created
In general, macros are created by stringing together a number of macro actions, each of which per-
forms a simple operation, such as setting the value of a field in a record.
Cross-Reference
In Chapter 30, you’ll read about user interface macros, which are primarily used to control the user interface
(opening forms and reports, responding to button clicks, and so on) and are an alternative to automating
Access with VBA code.
Access 2010 data macros share some of the advanced constructs available to user interface macros,
such as branching (the If action) and looping through recordsets (the ForEachRecord action).
Together, these constructs and the macro actions available to data macros combine to make a pow-
erful tool for Access data management.
Access 2010 data macros use the same macro editor used to create embedded and user interface mac-
ros. Once you master the macro editor, you’ll use it for all macro development and macro manage-
ment. The primary difference is that the action catalog (described later in this section) contains
different actions, depending on the context. By far the richest variety of macro actions is available to
user interface macros because they support a much greater variety of activity than data macros do.
Using the Macro Designer
The details of table events and macro actions are discussed in the following sections. In the mean-
time, let’s take a look at the Access 2010 Macro Designer to see how data macros work, and how
you use the Macro Designer to construct data macros.
Cross-Reference
In Chapter 30, you’ll learn more details of the Macro Designer’s features; in this chapter, we use the Macro
Designer as a tool only for constructing data macros.

Free download pdf