Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deactive auto save when closing a form?

Status
Not open for further replies.

KerryL

Technical User
May 7, 2001
545
US
When a user edits records on a form and then closes the form by clicking the "X" or by clicking on a "cmdClose" button, any changes that have been made are automatically saved, correct?

IOW, it's kind of a default setting that when you close a form it also does a save.

But what if I want the changes to be saved ONLY via a "cmdSave" button? How do I override the automatic save feature if I don't want the save command to be invoked every time the form is closed?

 
Hi!

You have a couple of options here.

First, make the form an unbound form and set up a form level recordset which you can use to move through the appropriate records and save when the button is clicked. You will need to prompt the user before exiting the form about saving any data they entered.

Second, add a form level variable in the general declarations portion of the form bolSaveRecord. In the form load event set the variable to false. Then in the BeforeUpdate event use the following code:

If bolSaveRecord = False Then
Me.Undo
Cancel = -1
End If

And in the save button's click event use the following code:

bolSaveRecord = True
DoCmd.RunCommand acRecordGoToNew

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top