After Update macro event
Applies to: Access 2013, Office 2013
The After Update event occurs after a record is changed.
Note
The After Update event is available only in Data Macros.
Remarks
Use the After Update event to perform any actions that you want to occur when a record is changed. Common uses for the After Insert include enforcing business rules, updating an aggregate total, and sending notifications.
You can use the Updated("Field Name") function to determine whether a field has changed. The following code example shows how to use an If statement to determine determine whether the PaidInFull field has been changed.
If Updated("PaidInFull") Then
/* Perform actions based on changes to the field. */
End If
You can use access a the previous value in a field by using the following syntax.
[Old].[Field Name]
For example, to access the previous value of the QuantityInStock field, use the following syntax.
[Old].[QuantityInStock]
The previous values are deleted permanently when the After Update event ends.
The following table lists macro commands can be used in theAfter Update event.
Command Type |
Command |
---|---|
Program Flow |
|
Program Flow |
|
Program Flow |
|
Data Block |
|
Data Block |
|
Data Block |
|
Data Block |
|
Data Action |
|
Data Action |
|
Data Action |
|
Data Action |
|
Data Action |
|
Data Action |
|
Data Action |
|
Data Action |
|
Data Action |
|
Data Action |
|
Data Action |
|
Data Action |
|
Data Action |
To create a Data macro that captures the After Update event, use the folloiwng steps:
Open the table for which you want to capture the After Update event.
On the Table tab, in the After Events group, click After Update.
An empty data macro is displayed in the macro designer.
Example
The following code example uses the After Update event to run a named data macro that adds a record to the Comment table each time the status of an issue is updated.
Click here to view a copy of the macro that you can paste into Macro Designer.
To view this example in the macro designer, use the following steps:
Open the table for which you want to capture the After Update event.
On the Table tab, in the After Events group, click After Update.
Select the code in the following code example and then press CTRL+C to copy it to the Clipboard.
Activate the macro designer window and then press CTRL+V.
<DataMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/04/application">
<DataMacro Event="AfterUpdate">
<Statements>
<ConditionalBlock>
<If>
<Condition>Updated("Status")</Condition>
<Statements>
<Action Name="RunDataMacro">
<Argument Name="MacroName">Comments.AddComment</Argument>
<Parameters>
<Parameter Name="prmRelatedID" Value="[ID]" />
<Parameter Name="prmComment" Value=""-- Status changed to " & [Status]" />
<Parameter Name="prmUserID" Value="[UserID]" />
</Parameters>
</Action>
</Statements>
</If>
</ConditionalBlock>
<ConditionalBlock>
<If>
<Condition>Updated("Resolution")</Condition>
<Statements>
<Action Name="RunDataMacro">
<Argument Name="MacroName">Comments.AddComment</Argument>
<Parameters>
<Parameter Name="prmRelatedID" Value="[ID]" />
<Parameter Name="prmUserID" Value="[UserID]" />
<Parameter Name="prmComment" Value=""-- Issue resolved as " & [Resolution]" />
</Parameters>
</Action>
</Statements>
</If>
</ConditionalBlock>
</Statements>
</DataMacro>
</DataMacros>
If Updated("Status") Then
RunDataMacro
Macro Name Comments.AddComment
Parameters
prmRelatedID = [ID]
prmComment ="--Status Changes to "&[Status]
prmUserID =[ChangedByUserID]
End If
If Updated("Resolution") Then
RunDataMacro
Macro Name Comments.AddComment
Parameters
prmRelatedID = [ID]
prmUserID =[ChangedByUserID]
prmComment ="--Issue Resolved as "&[Status]
End If