Access: Prompt for changes to be saved in Access 2003/XP/2000/97
Question: Access 2003/XP/2000/97 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 ifEnd 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.