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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dale FyeOwner, Developing Solutions LLCCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.