BeforeUpdate Prompt to Save Data

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
 
A

Allen Browne

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top