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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close Form Without Saving Information

Status
Not open for further replies.

mtwildtrout

Technical User
Oct 1, 2003
23
US
I have a Main & Subform as a data entry form. An Exit button is on the Subform. If the user enters partial information in the form (main or subform) then chooses to close the form, the partial information is saved.

I don't want any information saved if the Exit button or "X" close is clicked. I understand that this is the standard way Access handles the data. However, if I want to make sure none of this partial data gets into a table, how do I prevent it with code? I have thought about letting Access do its thing then delete the record after Access posts it to the table but I'm not exactly sure how & when to do it with code. Does anyone have any suggestions?

 
Probably the best way to go about this would be to leave the fields from the form Unbound. Then when someone clicks exit, check to ensure that all the fields which are required have values, if they do use an .addnew method of the forms recordset and add a new record with all the information, if all the information is not there, do not add the new record. That would seem like a relatively simple way to go about it.
 
Another would be to set the required fields parameter. To qoute MS Access Help the following would occur, Also the help has a routine to trap incomplete fields and display a message.

"If a form has a control bound to a field that has its Required property set to 'Yes,' and the form is closed using the Close method without entering any data for that field, an error message is not displayed. Any changes made to the record will be aborted. When the form is closed using the Windows Close button, the Close action in a macro, or selecting Close from the File menu, Microsoft Access displays an alert. The following code will display an error message when attempting to close a form with a Null field, using the Close method."
 
[tt]
Hi:

There's lots of ways. Here's another:

I'd try to "Undo" the record in the "OnClose" event of the form if all required data was not entered.

You could poll all the controls and if any were null, then "undo" the record before the form closes.

Cheers,[/tt]

[glasses][tt]Gus Brunston - Access2000(DAO Intermediate skills.
Webmaster: www.rentdex.com[/tt]
 
Hi mtwildtrout,

Hey, this is my first reply on the tek tips forums. I am still getting to grips with Access but I have been using a different option, ie. to close without saving data, eg.

DoCmd.Close acForm, "your form name", acSaveNo
Good luck
Zippy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top