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

Last reviewed: April 2, 1997
Article ID: Q99400
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

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

This article describes how to prompt the user to confirm changes to a field using a conditional macro.

MORE INFORMATION

This 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 : kbusage McrCond
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.