totn Access

MS Access 2007: Prompt for changes to be saved

This MSAccess tutorial explains how to set up a form to prompt for changes to be saved before saving in Access 2007 (with step-by-step instructions).

Question: Access 2007 automatically saves changes to the database when entering information on a form. How can I prompt a user to save changes like in other applications?

Answer: Since Access automatically save changes directly to the database, the only way to stop this from happening is to intervene on the Form_BeforeUpdate event. At this point, you can prompt the user to save or cancel changes.

For example, you could place the following code on the BeforeUpdate event for the form.

Private Sub Form_BeforeUpdate(Cancel As Integer)

   Dim LResponse as integer Dim LMsg as string

   LMsg = "Do you wish to save changes?"
   LResponse = msgbox(LMsg, vbYesNo, "Save changes")

   If LResponse = vbNo then
      DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
   End if

End Sub

In this example, before the changes are saved, the user is prompted with a message box. This message box asks the user if he/she wishes to save the changes. If the user responds "yes", then the changes are saved. If the user responds "No", then the changes are undone and the record is not updated.