Microsoft KB Archive/99400

= ACC: Using a Conditional Macro to Confirm Changes to a Field =

Article ID: 99400

Article Last Modified on 1/18/2007

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q99400



Moderate: Requires basic macro, coding, and interoperability skills.



SUMMARY
This article shows you how to use a conditional macro to prompt the user to confirm changes to a field.



MORE INFORMATION
The following procedure uses the Employees form in the sample database Northwind.mdb (or NWIND.MDB in versions 1.x and 2.0):

  Create the following new macro and save it as AreYouSure:

   Macro Name     Condition                      Action -   AreYouSure     MsgBox(&quot;Commit changes?&quot;,1)=2  CancelEvent ...                            SendKeys

AreYouSure Actions --   CancelEvent SendKeys Keystrokes: {ESC} Wait: NO

NOTE: The ellipsis in the Condition column forces Microsoft Access to perform the action on that line if the condition on the preceding line is true. Microsoft Access evaluates macro conditions as true or false. If the expression is true, Microsoft Access performs the action; if it is false, Microsoft Access ignores the action.  Open the Employees Form in Design view. On the View menu, click Properties. Click the Title text box to select it.  Set the properties for the Title text box as follows:

     Text box: Title ---     Name (or ControlName in version 1.x): Title ControlSource: Title BeforeUpdate: AreYouSure </li> View the form in Form view and change the information in the Title field. When a confirmation message appears, click OK to confirm your change, or click Cancel to cancel your change.</li></ol>

NOTE: This example uses the MsgBox function instead of the MsgBox action. The MsgBox action has only an OK Button whereas the MsgBox function can also include a Cancel button.

<div class="references_section">