Solved Me.Undo is reversing all the actions performed in a form (1 Viewer)

mrk777

Member
Local time
Today, 21:04
Joined
Sep 1, 2020
Messages
60
Hi Team, I have a bounded form with many fields and I have inserted the "Save" button to save the changes with the help of MsgBox (Yes/No). The problem is when I save it, it saves the form, but later if I change/modify one field and click on "No" to undo the changes, it is reversing all the actions that were performed and saved earlier. Is there any way that it can undo the changes made only after saved?

Below is the code I have used:
Code:
If Me.Dirty Then

    If MsgBox("Do you want to save the changes?", vbYesNo + vbQuestion, "Save Changes") = vbNo Then
        Me.Undo
    Else: Me.lbl_LastSaved.Caption = "Saved: " & Date & " " & Time
    End If

End If

Any suggestions, please...
 
Last edited:

Minty

AWF VIP
Local time
Today, 15:34
Joined
Jul 26, 2013
Messages
10,355
You aren't actually saving the record anywhere in that code. In fact that code is all wierdly laid out.
You need a Me.Dirty = False somewhere

Code:
If Me.Dirty Then

    If MsgBox("Do you want to save the changes?", vbYesNo + vbQuestion, "Save Changes") = vbNo Then
        Me.Undo
        Exit Sub
    End If
   
    Me.lbl_LastSaved.Caption = "Saved: " & Now()
    Me.Dirty = False
   
End If
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:34
Joined
Feb 28, 2001
Messages
27,004
Well, for starters you don't show us code that saves anything.

Putting a caption that says "Saved" doesn't initiate a save. All you are doing is accumulating changes - but never saving them (at least, not in that snippet you showed us.) The Undo will undo ALL accumulated changes since the last save.

Tell you what you should do... just to see what it looks like, create a command button using the command button wizard. One of the options is "Save Record" so activate that and then look at the code it generates. That will show you how to save form-based data.

Also, that ELSE: is suspicious. You don't need the colon and you should (for consistency's sake) put your "save it" actions in an indented code sequence just like the "don't save it" actions is indented. Consistent code formatting helps you by highlighting that you are in a code block that is isolated somewhat.
 

moke123

AWF VIP
Local time
Today, 11:34
Joined
Jan 11, 2013
Messages
3,852
You may not be saving it.
Access will save data if you move from the record on the form or if you explicitly save it.

try:
Code:
If Me.Dirty Then

    If MsgBox("Do you want to save the changes?", vbYesNo + vbQuestion, "Save Changes") = vbNo Then
        Me.Undo
    Else
         ME.DIRTY = FALSE
         Me.lbl_LastSaved.Caption = "Saved: " &Date, & " " & Time
    End If

End If
 

mrk777

Member
Local time
Today, 21:04
Joined
Sep 1, 2020
Messages
60
You aren't actually saving the record anywhere in that code. In fact that code is all wierdly laid out.
You need a Me.Dirty = False somewhere

Code:
If Me.Dirty Then

    If MsgBox("Do you want to save the changes?", vbYesNo + vbQuestion, "Save Changes") = vbNo Then
        Me.Undo
        Exit Sub
    End If
  
    Me.lbl_LastSaved.Caption = "Saved: " & Now()
    Me.Dirty = False
  
End If
Yeah, @Minty that correct, I'm not saving it as it is a bound form, any changes made, directly reflect into a Table. Sorry for that. Anyways this issue is solved with Me.Dirty=False.

Thanks a lot!! :)
 

Users who are viewing this thread

Top Bottom