Close a form without saving changes to database

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.
 
D

Dirk Goldgar

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top