Chapter 15: Using Access Data Macros
565
FIGURE 15.8
Using AfterInsert to add a record to tblProductActivityLog
Setting fields in the new record Create Record data block
In Figure 15.8, notice that three fields (ProductActivity, ProductID, and
ProductDescription) in tblProductActivityLog are being updated as part of the
CreateRecord data block. The ProductID is an AutoNumber field in tblProducts_
AfterInsert. The CreateRecord block has already added the record to the table, so the new
record’s ProductID value is available to this data macro. Therefore, when the SetField macro
action updates the ProductID field in tblProductActivityLog, the new product record’s
ID is successfully added to the log table.
tblProductActivityLog (shown in Figure 15.9) contains several fields (such as
ActivityDate) that are set by default values specified in the table’s design. ActivityDate is
set to the current date by a default assignment in the field’s properties, so there is no need to set
the ActivityDate field with the AfterInsert data macro.