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

ID: Q99400


The information in this article applies to:


SUMMARY

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

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):

  1. Create the following new macro and save it as AreYouSure:
    
        Macro Name     Condition                      Action
        ---------------------------------------------------------
        AreYouSure     MsgBox("Commit changes?",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.


  2. Open the Employees Form in Design view.


  3. On the View menu, click Properties.


  4. Click the Title text box to select it.


  5. 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 


  6. 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.


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.


REFERENCES

For more information about the Message box function, search the Help Index for "MsgBox Function."

Additional query words: forms macros data validation


Keywords          : McrCond 
Version           : 1.0 1.1 2.0 7.0 97
Platform          : WINDOWS 
Issue type        : kbinfo 

Last Reviewed: March 23, 1999