Access VBA Simple "undo" question

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

Patrick O'DeaAsked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Try this:

If MsgBox("Confirm This Change to IFG Status", vbOKCancel, _
    "OK Or Cancel") <> vbOK Then
    Me.IFGYesNocmb.Undo
    Cancel = True
End If
0
 
Dale FyeCommented:
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
0
 
PatHartmanCommented:
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.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Patrick O'DeaAuthor 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
0
 
Patrick O'DeaAuthor Commented:
Thanks Pat,

That's it!
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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?
0
 
Patrick O'DeaAuthor Commented:
Sorry Scott , I mis read the comments.

How can I re-allocate points?
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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.
0
 
Patrick O'DeaAuthor Commented:
Thanks,
All working well.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.