Undo change to checkbox in a form? (1 Viewer)

ITguy1981

Registered User.
Local time
Yesterday, 19:15
Joined
Aug 24, 2011
Messages
137
I have a form with a checkbox for the field "active". By default the box is checked. I currently have code to prompt the user if they have added or removed the check and asks if they would like to undo the action however if you undo the action it doesn't undo anything. Here is my code.

Private Sub Active_AfterUpdate()
Dim strmsg As String
strmsg = "The Clients active status has changed. "
strmsg = strmsg & "Do you want to keep the change?"
strmsg = strmsg & "Click <YES> to CONTINUE or <NO> to undo."
If MsgBox(strmsg, vbQuestion + vbYesNo, "Continue") Then
'Continue
Else
Me!Undo.Active
End If
End Sub

I've also tried me.undo and tried using DoCmd.RunCommand acCmdUndo
 

pr2-eugin

Super Moderator
Local time
Today, 00:15
Joined
Nov 30, 2011
Messages
8,494
Well Me.Undo, DoCmd.RunCommand all works at Form level.. i.e. they will undo all changes made to the Form until this point.
The best thing for you to do what I think will be.. to ask for confirmation inside the Before update event of the check box.
something like...
Code:
Private Sub Active_BeforeUpdate(Cancel As Integer)
    Dim strmsg As String
    strmsg = "The Clients active status has changed. "
    strmsg = strmsg & "Do you want to keep the change?"
    strmsg = strmsg & "Click <YES> to CONTINUE or <NO> to undo."
    If MsgBox(strmsg, vbQuestion + vbYesNo, "Continue") Then
        'Continue
    Else
        Cancel = True
    End If
End Sub
 

ITguy1981

Registered User.
Local time
Yesterday, 19:15
Joined
Aug 24, 2011
Messages
137
I put the code in the "before update" of the checkbox on the form. Is this the correct spot? When I put the code there and remove the check on the form I get the prompt. I click "no" to undo, but the check remains gone fromt he box.
 

pr2-eugin

Super Moderator
Local time
Today, 00:15
Joined
Nov 30, 2011
Messages
8,494
I think we need to work on the IF condition.. If they want to change the status, you say yes right? so..
Code:
    If MsgBox(strmsg, vbQuestion + vbYesNo, "Continue")=vbYes Then
        Cancel = True
    Else
        'Continue
    End If
Sorry about the mix up.
 

ITguy1981

Registered User.
Local time
Yesterday, 19:15
Joined
Aug 24, 2011
Messages
137
That didn't work either. That's okay. I've got code for any changed data in the whole form that asks to the user if they want to save on close. I was just going to for a little bit more dummy proofing.
 

Users who are viewing this thread

Top Bottom