Exiting Form/Subform without saving underlying data

I have a form and a subform and I need to  be able to
- a) save data from both forms (easy - default by access)
- b) exit both forms without saving any of the data (do I need to save first and then delete both records??)
- c) exit both forms and restore previous values of both forms (no clue how to achieve this easy?)

Thank you for any help on b or c ..
mpimAsked:
Who is Participating?
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
Unfortunately Access does not make this easy as it automatically saves the main form record as soon as you enter a sub form control.

But there are a few different ways to achieve this.

1. Use of temp tables for either main records, sub records, or both.

You give the user some means of finding a record, then when they click a "Edit" button, you copy the records to the temp tables, which are the same structure as the main/sub tables.

Then you base the form off the temp tables and give them a "save" and "cancel" button.

If they click Cancel, you need do nothing.   If they click save, then you need to update the main/sub records.

It's a bit tricky to do, but it does work.

2.  Use transactions.

 Starting with A2000, you can assign the form recordset.   That means you can wrap all the edits/adds in a transaction and either committ or cancel at any point.  Example of that is here:

http://www.databasedevelopment.co.uk/examples.htm

3. Use the "unbound" approach.

  Everything is unbound (no Recordsource or controlsource) and you get/put all the record data yourself handling the linking of the subform record, etc.

Which method depends on a lot of different things, but most opt for temp tables.

Jim
0
 
Dale FyeCommented:
If you must have the ability to rollback both the main and subforms, then the temp table method is what I use.

I also use the Form_BeforeUpdate (of both the main and subform) to ensure that required fields are all filled in before the user is allowed to save date in either of those forms.  You can also use the Exit event (it has a Cancel argument) of the subform control to ensure that required fields in the subform have been filled in before allowing the user to set the focus outside the subform.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.