Help with subform, please

  • Thread starter Thread starter Ig
  • Start date Start date
I

Ig

Hi,
I have a main form, subform in it, and two command buttons on the main
form -
"Save and Close" and "Cancel and Close".
What code should I put into "Cancel and Close" button in order to undo
changes in the subform
as well? Putting Undo code for subform there seems already late.
Generally, what are the guidelines for saving or undoing updates in such
structure?
Thanks
 
Hi,
I have a main form, subform in it, and two command buttons on the main
form -
"Save and Close" and "Cancel and Close".
What code should I put into "Cancel and Close" button in order to undo
changes in the subform
as well? Putting Undo code for subform there seems already late.
Generally, what are the guidelines for saving or undoing updates in such
structure?

My guideline would be... don't set it up so you need to do that,
because it's a MAJOR hassle.

In a Form/Subform structure, the main form record is saved to disk the
instant you start to modify any record on the subform. It's already
saved - it's too late to undo.

Similarly, each subform record is saved to disk the instant you move
off the record, either to another subform record or to the main form.

In order to "Cancel and Close" you must run two Delete queries to
delete the mainform record, and all of the subform records. It can be
done but as I say... it's a hassle.

John W. Vinson[MVP]
 
so what is the best approach?

John Vinson said:
My guideline would be... don't set it up so you need to do that,
because it's a MAJOR hassle.

In a Form/Subform structure, the main form record is saved to disk the
instant you start to modify any record on the subform. It's already
saved - it's too late to undo.

Similarly, each subform record is saved to disk the instant you move
off the record, either to another subform record or to the main form.

In order to "Cancel and Close" you must run two Delete queries to
delete the mainform record, and all of the subform records. It can be
done but as I say... it's a hassle.

John W. Vinson[MVP]
 
so what is the best approach?

A choice of evils:

- Train your users that when they enter data on a form, it's entered.
If they're not certain they want to enter data... don't start until
they ARE certain.

- Or, write the (application specific) VBA code to run a Delete query
to delete the records. Any time you run delete queries you need to be
very cautious, since deletion is irreversible; be CERTAIN that the
code is deleting the *right* records.

I'd really hesitate to post code to do this, since I don't know your
database or your business constraints. I'd hate to post some code that
*looks* like it would work only to find out that when you implemented
it you deleted the last four years of production data (which *could*
happen).


John W. Vinson[MVP]
 
Another choice is to create a temp table with the information from the
parent table and bind controls to the temp table. If a user then wants
to close/cancel, the information has not been added to the real
database tables. When the user is ready to save, have a command button
that joins the temp table with the parent table and append or update.
 

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

Back
Top