We help IT Professionals succeed at work.

Access VBA Simple "undo" question

Patrick O'Dea
on
See my VBA which does a msgbox "beforeupdate".
Question: If I click "cancel" in the msgbox WHY does it NOT undo the change I made to the control IFGYesNocmb.  Do I need to do some thing else??

Private Sub IFGYesNocmb_BeforeUpdate(Cancel As Integer)
If MsgBox("Confirm This Change to IFG Status", vbOKCancel, _
    "OK Or Cancel") <> vbOK Then
    Me.IFGYesNocmb.Undo
    Exit Sub
End If

End Sub

Open in new window

Comment
Watch Question

Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014
Commented:
Try this:

If MsgBox("Confirm This Change to IFG Status", vbOKCancel, _
    "OK Or Cancel") <> vbOK Then
    Me.IFGYesNocmb.Undo
    Cancel = True
End If
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
No points please.

I think you can remove the UNDO line and simply use Scott's line:

If MsgBox("Confirm This Change to IFG Status", vbOKCancel, _
    "OK Or Cancel") <> vbOK Then
    Cancel = True
End If
Distinguished Expert 2017
Commented:
Both lines are necessary if you want to back out the change as well as cancel the update.

"Cancel = True", cancels the control/record save but does not alter the "new" value

Me.somefield.Undo, backs out the change to the specified control and resets the control to the original value.
Me.Undo, backs out the change to the current record and resets all controls to their original values.

Author

Commented:
folks, I tried the "Cancel=True" but no joy.
See attached frmMain.   Perhaps because it is a "combo" or perhaps the continuous form causes a complication.

See 20 second video
http://screencast.com/t/lii9Pl7LDwyT
IFG1.accdb

Author

Commented:
Thanks Pat,

That's it!
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:
I don't quite follow. Seems my code was the solution, with Pat's explanation being followup, so I'm not clear on the point award. Can you please explain why you awarded points in that manner?

Author

Commented:
Sorry Scott , I mis read the comments.

How can I re-allocate points?
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:
You can ask the Mods to reopen the question. Just use the Request Attention link at the top of your question, just below the original text.

Author

Commented:
Thanks,
All working well.