What does 'Dirty' refer to?

Alc

Registered User.
Local time
Today, 05:16
Joined
Mar 23, 2007
Messages
2,421
I have a form displaying data. On this form I have 'Save' and 'Cancel' buttons. My problem is that the code behind the 'Cancel' button (see following) doesn't seem to recognize when an alteration has occurred.
Code:
If Me.Dirty Then
      MsgBox "Changed"
      Me.Undo
Else
      MsgBox "No Change"
End If
No matter which field(s) I change, the code always hits the 'No Change' part and the alterations are saved.

What needs to happen for the 'Dirty' part to be applicable?:confused:
 
Dirty means that the record has been created or amended on screen but not yet saved in the underlying tables.
 
Dirty checks to see if the record has changed since it was last saved.

Try doing a Me.Refresh before the if statement.
 
Thanks both. I was sort of hoping I'd misunderstood the meaning, but it appears not.

Me.Refresh didn't help, unfortunately. The 'No Change' part is still being reached and the record is still getting saved.
 
I think something else is going on. If you move the Me.UnDo outside of the If statement, does the record still save? What mechanism are you using to save the record? Just exiting the form?
 
Last edited:
Just as a "duh" type question... is the form bound or were you doing explicit recordset operations behind the scenes?
 
I think something else is going on. If you move the Me.UnDo outside of the If statement, does the record still save? What mechanism are you using to save the record? Just exiting the form?

Once again I'm torn between feeling embarrassed at having missed it myself and relieved that there are at least some other people capable of spotting my errors (as I don't seem able).:o

Your comments pointed me in the right direction and the problem was as follows:
Prior to the 'If Me.Dirty Then' bit, I was resetting the subform's Link fields. I didn't include this code in my sample, as as I thought it irrelevant. It never occurred to me that this would cause a save of the entered data (presumably because the focus was now being shifted?). Anyway, I tried commenting this part out and everything worked fine. What I've ended up with is running the 'If Me.Dirty Then' section then resetting the link fields. This works as required.

Thanks for the help.
 

Users who are viewing this thread

Back
Top Bottom