ACC2002: BeforeUpdate and AfterUpdate Properties Are Not Working (289895)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q289895
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

For a Microsoft Access 2000 version of this article, see 201088.

SYMPTOMS

The macro or function that is attached to the BeforeUpdate or AfterUpdate property of a bound control does not run when expected.

CAUSE

The BeforeUpdate and AfterUpdate events of a bound control are not triggered if the bound control is first modified by a macro or by code.

RESOLUTION

You can work around this behavior by causing the macro or the code that modifies the bound control to manually trigger the event that is pointed to by the BeforeUpdate or AfterUpdate property of the bound control.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open the sample database Northwind.mdb.
  2. Create the following macro, and name it TestCityForNull:
       Macro Name       Condition        Action
       ---------------------------------------------
       TestCityForNull  IsNull([City])   MsgBox
                        ...              CancelEvent
    
    
       TestCityForNull Action Arguments
       ----------------------------------
       MsgBox:
       Message: City Is A Required Field!
    					
  3. Create the following macro, and name it SetCityToNull:
       Macro Name        Action
       ------------------------------
       SetCityToNull   OpenForm
                       SetValue
    
    
       SetCityToNull Action Arguments
       -------------------------------
       OpenForm Action:
       FormName: Customers
       View: Form
    
       SetValue Action:
       Item:[Forms]![Customers]![City]
       Expression: Null
    					
  4. Open the Customers form in Design view, and then select the TestCityForNull macro in the BeforeUpdate property of the City control.
  5. Run the SetCityToNull macro. Note that it successfully blanks out the City field (you can press ESC twice to get it back). If the BeforeUpdate event of the control had been triggered, the TestCityForNull macro would not have allowed the field to be blank.
  6. Try to blank out the City field manually. Note that the TestCityForNull macro is triggered and displays the following message:

    City Is A Required Field!

  7. Do not save changes when you close the Customers form.

Modification Type:MajorLast Reviewed:11/6/2003
Keywords:kbprb KB289895