Saturday, September 19, 2009

Access Form: Cancel Changes Button

When you enter values in Access forms, and later decided to discard them, there is no ready button that can do such thing. The Cancel button as provided by Access form wizard just simply closes the form. As anybody familiar with Access, once you typed something in forms that are bound to tables, those values are automatically registered as new record.

Below is my workaround in creating a Cancel button that actually undo any changes and close the form. This is Access 2007 embedded macro set for the Cancel button.
Condition
Action
Arguments
Comment
On Error
Next,
[Form].[Dirty]
RunCommand
Undo
Perform Undo only when form content is modified, else, skip
[MacroError]<>0
MsgBox
=[MacroError].[Description], Yes, None,
Spit out the error message from system
Close
, , Prompt

No comments:

Post a Comment