Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Use a Conditional Macro to Confirm Changes to a Field


View products that this article applies to.

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

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

↑ Back to the top


Summary

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

↑ Back to the top


More information

To use a conditional macro to prompt the user to confirm changes to a field in a form, follow these steps:

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

  1. Start Microsoft Access, and then open the sample database Northwind.mdb or the sample project NorthwindCS.adp.
  2. In the Database window, click Macros, and then click New. On the View menu, click Conditions to display the Condition column. Create the following new macro:
       Condition                      Action         Action Arguments
       -------------------------------------------------------------------
       MsgBox("Commit changes?",1)=2  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. Access evaluates macro conditions as true or false. If the expression is true, Access performs the action; if it is false, Access ignores the action.

  3. Save the macro as AreYouSure.
  4. In the Database window, click Forms, click Employees, and then click Design to open the Employees form in Design view.
  5. On the View menu, click Properties to open the property sheet, if it is not already open.
  6. Click the Title text box to select it.
  7. Set the Before Update property for the Title text box to AreYouSure.
  8. On the View menu, click Form View. Change the information in the Title field. Press the TAB key to move to the next 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.

↑ Back to the top


References

For more information about the MsgBox function, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type msgbox function in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB209549, kbinfo, kbhowto

↑ Back to the top

Article Info
Article ID : 209549
Revision : 2
Created on : 6/24/2004
Published on : 6/24/2004
Exists online : False
Views : 281