Table of contents
XML
TOC
Collapse the table of content
Expand the table of content

Prompt a User Before Saving a Record

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

The following example illustrates how to use the BeforeUpdate event to prompt users to confirm their changes each time they save a record in a form.

Private Sub Form_BeforeUpdate(Cancel As Integer) 
   Dim strMsg As String 
   Dim iResponse As Integer 

   ' Specify the message to display. 
   strMsg = "Do you wish to save the changes?" &; Chr(10) 
   strMsg = strMsg &; "Click Yes to Save or No to Discard changes." 

   ' Display the message box. 
   iResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") 

   ' Check the user's response. 
   If iResponse = vbNo Then 

      ' Undo the change. 
      DoCmd.RunCommand acCmdUndo 

      ' Cancel the update. 
      Cancel = True 
   End If 
End Sub
© 2018 Microsoft