Microsoft Office Tutorials and References
In Depth Information
Attaching Macros to Tables
To edit a data macro for a table, open the table in Design view; click the
Create Data Macros button in the Field, Record & Table Events group on the
Design tab of the Ribbon; and choose the same event you chose before —
that is, follow the same steps you used to create the macro. Access displays
the macro that’s saved for that event. (We think that the button should be
called Create or Edit Data Macros, but a name that long would never fit on
the Ribbon!)
The one feature to which this dual functionality doesn’t apply is named
macros. You create a named macro with the Create Named Macro option,
and you edit a named macro with the Edit Named Macro option. Named
macros give you added flexibility. You can invoke them by name, as well
as have them execute when a triggering event occurs. You might create a
named macro called SendEmail to send an e-mail message to an operator
whenever a certain error condition occurs, for example.
Book VI
Chapter 2
You have just one data macro for each triggering event for the table, not a
separate macro for each field. If you want to update two different fields in a
record, your macro can have two SetField actions. While a data macro is
open in Design view, you can’t view any other Access objects until you close
the macro; we’re not sure why. This limitation is inconvenient, and we hope
that Microsoft considers it to be a bug and fixes it.
Data macros don’t show up on the Navigation Pane; they aren’t considered
to be separate objects. They’re stored as part of the table to which they’re
Trying cool data-macro tricks
Here are a couple of questions that show the kind of things you can find out,
using functions and properties in data macros:
Did the value of this field even change? When you write a data
macro triggered by an AfterUpdate or BeforeChange event —
by an edit of the record — how can you tell whether the value of
a specific field changed? Maybe the record was edited, but who
knows which fields actually changed? You can find out by using the
Updated(“ fieldname ”) function. The following condition, for
example, is True only if the ProductCount field in the Orders table changed
and the value of that field is less than 6:
If Updated(“ProductCount”) And ProductCount < 6
What did the value used to be? If the value of a field changed, you may
want to know what the previous value was. If the ProductCount went
up, for example, you may want to do something about recalculating the
shipping charge. You can use the Old.[ fieldname ] property for a
value that the field had before the edit. (Note that you don’t use
quotation marks around the field name.)
Search JabSto ::

Custom Search