Check if any changes have been made to the record

bignate

Registered User.
Local time
Yesterday, 22:27
Joined
Aug 28, 2013
Messages
34
I use the code below when a form is closed to either save or undo changes. However I only want the msg box to appear if there have been any changes to the record that the form is based on, if there aren't any changes then it will just docmd.close without the msgbox. How would I check if there have been any changes to the record? I think you have to use 'Dirty' but im not really sure how to use it.

Private Sub CLoseUR_Click()

Dim strMsg As String, strTitle As String

strMsg = "Do you want to save changes?"
strTitle = " Save Changes?"

If ValidateForm Then
Else
If MsgBox(strMsg, vbQuestion + vbYesNo, strTitle) = vbNo Then
Me.Undo
DoCmd.Close
Else
DoCmd.Close
End If
End If
End Sub
 
me.dirty if I remember correctly will hold the "if the form has been changed"

However it will be dirty if a user adds a space and removes it again using backspace as well.
 
In addition to the comments by namliam, IMHO it would be better to have validation code in the form's Before Update event.
 
I just got Me.Dirty to work, thanks guys.
Bob Fitz are you suggesting I use Me.Dirty in the BeforeUpdate?
 

Users who are viewing this thread

Back
Top Bottom