You are currently offline, waiting for your internet to reconnect

ACC2000: How to Prompt User to Save Changes to Record in a Form

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

When you move to the next record on a form or close a form, MicrosoftAccess automatically saves any changes that you have made to the currentrecord. This article shows you how to use a BeforeUpdate event procedure toprompt you to verify the save operation before Microsoft Access willcontinue.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
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.

This example uses the BeforeUpdate event procedure in the Customers form toprompt the user to confirm changes before Microsoft Access will save therecord:
  1. Open the sample database Northwind.mdb, and open the Customers form in Design view.
  2. Set the form's BeforeUpdate property to the following event procedure:
    Private Sub Form_BeforeUpdate(Cancel As Integer)   ' This procedure checks to see if the data on the form has   ' changed. If the data has changed, the procedure prompts the   ' user to continue with the save operation or to cancel it. Then   ' the action that triggered the BeforeUpdate event is completed.   Dim ctl As Control   On Error GoTo Err_BeforeUpdate   ' The Dirty property is True if the record has been changed.   If Me.Dirty Then      ' Prompt to confirm the save operation.      If MsgBox("Do you want to save?", vbYesNo + vbQuestion, _              "Save Record") = vbNo Then         Me.Undo      End If   End IfExit_BeforeUpdate:   Exit SubErr_BeforeUpdate:   MsgBox Err.Number & " " & Err.Description   Resume Exit_BeforeUpdateEnd Sub					
  3. On the Debug menu, click Compile Northwind.
  4. On the File menu, click Save Northwind.
  5. On the File menu, click Close And Return to Microsoft Access.
Now, when you make a change to a record, and then you either move to adifferent record or close the form, you are prompted to confirm that youwant to save the current record. If you click No, the record is reset and the operation continues as normal.

Article ID: 197103 - Last Review: 06/23/2005 23:22:00 - Revision: 3.0

  • Microsoft Access 2000 Standard Edition
  • kbhowto kbdtacode KB197103