Chapter 15: Using Access Data Macros
561
to USysApplicationLog anytime you want from a data macro. The only field in
USysApplicationLog that can be written using LogEvent is Description, a
memo type field. The other fields in USysApplicationLog (Category, Context,
DataMacroInstanceID, ErrorNumber, ObjectType, and SourceObject) are
provided by the macro itself.
l SendEmail: This macro action, obviously, sends an e-mail using the default Windows
e-mailer (usually Microsoft Office Outlook). The arguments for SendEmail are: To, CC,
BCC, Subject, and Body. SendEmail is quite useful in certain situations, such as auto-
matically dispatching an e-mail when an error condition occurs, or when a product’s
inventory level falls below some threshold.
l (^) SetField: The SetField action updates the value of a field in a table. The arguments
to SetField include the table and field names, and the new value to assign to the field.
SetField is not available to BeforeChange and BeforeDelete table events.
l SetLocalVar: Access 2010 macros are able to use local variables for passing values from
one part of a macro to another. For example, you might have a macro that looks up a
value in a table and passes the value as a variable to the next macro action. SetLocalVar
is an all-purpose variable declaration and assignment action that creates a variable and
assigns a value to it.
l (^) StopMacro: The StopMacro action interrupts the currently executing macro, causing it
to terminate and exit. Most often used in conjunction with an If data block, or in the
destination of an OnError macro action, there are no arguments to StopMacro.
l StopAllMacros: This macro action is parallel to StopMacro, except that it applies to
all currently executing macros. Macros may run asynchronously because table events
might launch multiple macros at one time, or a macro might call a named macro as part of
its execution.
l RunDataMacro: This macro action is very simple. Its only argument is the name of some
other data macro that Access runs. RunDataMacro is useful in situations where a certain
data macro performs some task that another data macro finds useful. Instead of duplicat-
ing the macro’s actions, it’s simpler just to call the macro and allow it to perform its
actions as a single operation.
l (^) OnError: The OnError macro action is the heart of Access 2010 macro error handling.
OnError is a directive that tells Access what to do in the event an error occurs during a
macro’s execution. The first argument (GoTo) is required, and is set to either Next,
Macro Name, or Fail. Next directs Access to simply ignore the error and continue exe-
cution at the macro action following the action that caused the error.
Unless another OnError is positioned within the data macro, OnError GoTo Next tells
Access to ignore all errors in the data macro, and continue execution regardless of what-
ever errors occur. The Macro Name directive names a macro you want to jump to in the
event of an error. The destination of Macro Name is a named macro, which is just a col-
lection of macro actions not attached to a table event. The Macro Name destination could
be a named macro within the current table, or in another table.