BeforeUpdate Prompt to Save Data

  • Thread starter Thread starter Carolyn
  • Start date Start date
C

Carolyn

I have a macro that prompts a user regarding saving changes prior to
exiting the database. It is in the beforeupdate section of the form.
How would I modify the code to only prompt save if data has changed?
The way it is now, you are prompted if you only view the form.

Thank you in advance for any help.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
strMsg = "Data has changed."
strMsg = strMsg & "Do you wish to save the changes?"
strMsg = strMsg & "Click Yes to Save or No to Discard changes."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes
Then
'do nothing
Else
DoCmd.RunCommand acCmdUndo
End If
End Sub
 
The form's BeforeUpdate event does not fire if you only view the form.

There must be some other code or action that is dirtying the form whenever
the user views the record. For example, code in the Current event of the
form could dirty the record as soon as you move there.
 
Back
Top