MS-Access / Getting Started

Calling Named Data Macros

We mentioned earlier that named data macros must be called for Access to execute them. If you want to test out a named data macro, you must therefore call a RunDataMacro action from a table event, a user interface macro, or from Visual Basic. For simplicity of this example, we'll create a data macro attached to a table event that will trigger the named data macro to execute. Close the tblErrorLog table, if you still have it open, and then open the tblAppointments table in Datasheet view. Let's call the new named data macro you created to run whenever you insert a new record into the tblAppointments table. Click the Table contextual tab and then click the After Insert button in the After Events group to open the Logic Designer. To call the named data macro to run, you need to use the RunDataMacro action. By now, you should be very familiar with the different techniques for adding a new data action to the macro design surface. In this case, we'll do something different because we are calling a named data macro. In the Action Catalog, expand the In This Database node near the bottom of the screen. Next, expand the Tables node beneath In This Database, and then expand the tblErrorLog node to see the named data macros attached to this table.

Now, drag the ClearLogsTest named data macro that you created in the previous section onto the macro design surface. Access adds a new RunDataMacro data action to the macro design surface and also fills in the required Macro Name argument for you. The Macro Name argument requires the name of the table and the name of the named data macro separated by a period. Access also provides a drop-down list for this argument where you can select from a list of all the named data macros attached to the tables in your database.

To test out the named data macro, save the changes to this After Insert event and then create a new record in the tblAppointments table. After you insert a new record into the table, Access executes the RunDataMacro action and then deletes all the records in the tblErrorLog table. You can verify this by opening the tblErrorLog table and seeing that no records exist in the table.

[Previous] [Contents] [Next]