Close a form without saving changes to database

  • Thread starter Thread starter Lisa
  • Start date Start date
L

Lisa

Access automatically saves changes to a database via the
form. I want to add a button to the form to allow the
user to exit the form without recording the information he
has just inputted into the form. Basically, how do I add
a "cancel and close" button. Thanks.
 
Lisa said:
Access automatically saves changes to a database via the
form. I want to add a button to the form to allow the
user to exit the form without recording the information he
has just inputted into the form. Basically, how do I add
a "cancel and close" button. Thanks.

Code for such a button would be something like:

Private Sub cmdCancel_Click()

If Me.Dirty Then Me.Undo

DoCmd.Close acForm, Me.Name, acSaveNo

End Sub

Note: specifying "acSaveNo" on the DoCmd.Close call doesn't prevent the
data changes from being saved -- it's only there to prevent design changes
(sorts, filters, etc.) from being saved. It's the Me.Undo that undoes all
the data changes.
 
Back
Top