Uses of Data Macros

Access 2010 provides various types of data macro actions that you can attach to table events to automate your application. With data macros, you can:

As you’ll learn in Chapter 20, and Chapter 21, Access 2010 supports user interface macros to control application flow in your forms and reports and to respond to user actions. You can also utilize user interface macros, as well as Visual Basic, to enforce complex business logic that might not be covered by table relationships, unique properties, validation rules, and required properties. The potential problem with using user interface macros and Visual Basic to enforce complex business logic, however, is that you don’t always have complete control over how users interact with the data in your tables. For example, users can add, update, and delete data through queries. Users can also link to the tables in one Access database file from another Access file and add, update, and delete data from that database. In both of these examples, users can bypass your complex business logic rules normally stored in user interface macros and Visual Basic code. (You’ll learn all about queries in Part III, and linking Access files in Chapter 8.)

Access 2010 introduces a new type of macro, called data macros, to provide a place for Access developers to centralize all their business logic and rules. Data macros are similar to triggers in Microsoft SQL Server because they allow you to attach business logic directly to table events. However, unlike triggers in SQL Server, data macros are not performed within a transactional context—each operation is separate. Data macros respond to data modifications, so no matter how users edit data in the database, Access enforces those rules. This means you can write business logic in one place, and all the data entry forms and Visual Basic code that update those tables inherit that logic from the data layer. Once you create a data macro for a table event, Access runs the data macro no matter how you change the data.

Data macros in Access 2010 can be used in both client and web databases. In fact, the events, actions, and properties that you can use in data macros are identical between client and web databases, so you can easily reuse data macros that you defined in a client database for use in a web database. The Access database engine enforces data macros when you work with a client database. When you publish a web database to a Microsoft SharePoint 2010 server, Access Services enforces data macros on the server through the use of SharePoint Workflow actions.

Inside Out: Important Considerations Using Data Macros

When you’re adding data macro logic to your client and web tables, you need to be aware of these important issues: