You can reset
Dirty without leaving the
Form, with a simple
If Me.Dirty then Me.Dirty = False
or even
DoCmd.RunCommand acCmdSaveRecord
but you
can't do it from the
OnDirty event!
But to be honest, if a pencil hits the keyboard, or an errant elbow, or a flying squirrel, how is
locking the
Form, after
X amount of idle time, going to prevent this, or even make them aware that it occurred?
What you really need to do is to use
validation code to ask the user what they want to do, if a
Form has been
Dirtied, i.e had
data entered or
data edited, when they try to
leave the Record,
close the Form or
close Access, itself. At this point the
Form_BeforeUpdate event fires, so ask them if they want to
save or
dump the
New Record or the
changes to an existing Record:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not (Me.NewRecord) Then
If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
Me.Undo
End If
Else
If MsgBox("Would You Like To Save This New Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This New Record ???") = vbNo Then
Me.Undo
End If
End If
End Sub
This will at least remind them to check the
data, one last time, before the
Record is saved.
If you just
have to lock the Form after X amount of time, Sean's approach is the correct one, but it's not going to guarantee that data won't be accidentally changed.
Linq
;0)>