Microsoft KB Archive/201088

= ACC2000: BeforeUpdate and AfterUpdate Properties Not Working =

Article ID: 201088

Article Last Modified on 7/14/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q201088



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 2002 version of this article, see 289895.



SYMPTOMS
The macro or function 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 code that modifies the bound control to manually trigger the event pointed to by the BeforeUpdate or AfterUpdate property of the bound control.



Steps to Reproduce Behavior
 Open the sample database Northwind.mdb.  Create the following macro called TestCityForNull:   Macro Name       Condition        Action -  TestCityForNull  IsNull([City])   MsgBox ...             CancelEvent

TestCityForNull Action Arguments --  MsgBox: Message: City Is A Required Field!   Create the following macro called SetCityToNull:   Macro Name        Action --  SetCityToNull   OpenForm SetValue

SetCityToNull Action Arguments ---  OpenForm Action: FormName: Customers View: Form

SetValue Action: Item:[Forms]![Customers]![City] Expression: Null  Open the Customers form in Design view and select the TestCityForNull macro in the City control's BeforeUpdate property.</li> Run the SetCityToNull macro. Note that it successfully blanks out the City field (you can press ESC twice to get it back). If the control's BeforeUpdate event had been triggered, the TestCityForNull macro would not have allowed the field to be blank.</li> Try to blank out the City field manually. The TestCityForNull macro will be triggered, displaying the following message:

City Is A Required Field!

</li> Do not save changes when you close the Customers form.</li></ol>

<div class="references_section">