Undo Changes

J

Jason

Hi there

I am using the following code in the before update event. the purpose of
this, is to allow any accidental changes to values in a field, to be undone.
However... I have a couple of issues, that I am hoping someone might be able
to offer advice on.

1) Is it possible for this code to only be applied if the record is a saved
record. Meaning that, if a user is adding a new record. the message will not
display, or if the field being updated is blank (No current values).
2) I noticed that deleting a value in a field is not considered a change. I
tested the code, and when I add a character to the field, the message
displays, but if I delete the values in the field, then the message does not
display

Here is the code:

Private Sub TXT_PROPERTY_BeforeUpdate(Cancel As Integer)
'==========================================================================
' This gives the user the opportunity to undo changes, where changes are
' not valid
'==========================================================================

msg = "Changes have been detected in this field " & vbCr
& vbCr
msg = msg & "Would you like to save these changes?"

If Not IsNull(Me.TXT_PROPERTY) Then
If MsgBox(msg, vbQuestion + vbYesNo, "Removed Company Name") = vbNo Then
Me.Undo
End If
End If
End Sub
 
J

John W. Vinson

Hi there

I am using the following code in the before update event. the purpose of
this, is to allow any accidental changes to values in a field, to be undone.
However... I have a couple of issues, that I am hoping someone might be able
to offer advice on.

1) Is it possible for this code to only be applied if the record is a saved
record. Meaning that, if a user is adding a new record. the message will not
display, or if the field being updated is blank (No current values).

You can use

If Me.NewRecord Then
<do one thing>
Else
2) I noticed that deleting a value in a field is not considered a change. I
tested the code, and when I add a character to the field, the message
displays, but if I delete the values in the field, then the message does not
display

Remove the check for IsNull(Me.TXT_PROPERTY) then; if the user blanks out the
field, it will be NULL and your If statement will cause your code to be
skipped.
 

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