Microsoft Access 2010 Bible

(Rick Simeone) #1

Part II: Programming Microsoft Access


564


FIGURE 15.7

Using IsInsert to determine if BeforeChange fired as the result of adding a new record.


IsInsert property Nested If block

If block


After events
The “after” events (AfterChange, AfterInsert, and AfterDelete) are more robust than
their “before” counterparts. Each of these events supports the entire family of data-macro actions
(DeleteRecord, SetField, SendEmail, and so on), so it’s likely that you’ll frequently use
these events as the basis of your data macros.

Most important, perhaps, is that the “after” events can use the ForEachRecord macro block
to iterate over recordsets provided by tables or queries. This ability makes these events ideal for
scanning a table for consistency or to add a record to a log table or perform some other compute-
intensive updates.

Figure 15.8 shows a typical use of the AfterInsert event. The AfterInsert event fires when-
ever a new record is added to a table. The new record has already been committed to the table and
AfterInsert is used to update a table name tblProductActivityLog.
Free download pdf