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

Comment macro statement

Program Flow

Group macro statement

Program Flow

If...Then...Else macro block

Data Block

CreateRecord macro action

Data Block

EditRecord macro action

Data Block

ForEachRecord macro action

Data Block

LookupRecord data block

Data Action

CancelRecordChange macro action

Data Action

ClearMacroError macro action

Data Action

DeleteRecord macro action

Data Action

ExitForEachRecord macro action

Data Action

LogEvent macro action

Data Action

OnError macro action

Data Action

RaiseError macro action

Data Action

RunDataMacro macro action

Data Action

SendEmail macro action

Data Action

SetField macro action

Data Action

SetLocalVar macro action

Data Action

StopAllMacros macro action

Data Action

StopMacro macro action

To create a Data macro that captures the After Update event, use the folloiwng steps:

  1. Open the table for which you want to capture the After Update event.

  2. 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:

  1. Open the table for which you want to capture the After Update event.

  2. On the Table tab, in the After Events group, click After Update.

  3. Select the code in the following code example and then press CTRL+C to copy it to the Clipboard.

  4. 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="&quot;-- Status changed to &quot; &amp; [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="&quot;-- Issue resolved as &quot; &amp; [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