Solved: Cancel and Undo with Macro
I have a macro that I want to run on the BeforeUpdate event for a close date. There is another macro that runs on the AfterUpdate event.
The BeforeUpdate macro validates whether the person has permission to close out the order (by adding a date to the closed on field).
Currently if the validation fails, it runs CancelEvent and then calls Undo. This stops the event and clears the text box, but then it treats the Undo as an update and runs the BeforeUpdate again.
Anyone have any ideas on how to just restore the previoius data in a clean manner?
Cancel and Undo changes/No more Macro....
Type Mismatch. Error 13.
A few of the processes call the acNext, then acPrevious to force the save, and it appears that calculated fields aren't calculated after that step. If I capture those values before any other checks are made, it works just fine.
In the end I converted her macro and did it my way with old fashioned VBA.:cloud9:
The macro feature seems pretty cool though for 2007 applications. I look forward to trying my hand at those a little more.
I still am struggling with the BeforeUpdate though. If the validation fails, I undo the change, and cancel the event. But if I try to leave the field it continues to call the BeforeUpdate method until the user hits ESC. Can I automate this somehow?
[vba]If ((m_NeedsReview = True) And (Not IsNull(Me.RR_Out_Date) Or Me.RR_Out_Date <> "")) Then
MsgBox "Total Exposure is higher than your authorized limit to approve." & VbNewline & _
Please remove the invalid data to proceed. Or press {ESC}.", vbOKOnly, ""
DoCmd.RunCommand acCmdUndo
DoCmd.CancelEvent
End If
[/vba]