do not save data on subForm


D

dsc2bjn

I have form which contains a subform. I placed code in the main form to not
save the information, if the user clicks on a "Close without Saving" button.
If the subform contains data, the record is saved anyway. How can I drop
the subform data if the user click on the "Close without Saving" button?

Code in my main form:

If Me.Dirty Then

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
DoCmd.Close
 
Ad

Advertisements

J

Jeanette Cunningham

hi dsc2bjn,
it's more tricky with a subform.
The way access works is to save any data in the subform as soon as the user
clicks out of the subform onto the main form or any control on the main
form.
You could set the subform's data property to set allow edits, allow
deletions, allow additions and data entry to No. This would prevent the user
making any changes to the data in the subform.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
D

dsc2bjn

If I do as you suggest, the user wouldn't be able to enter any new
(subform)records or update any (subform) records.

My gut is telling me to allow the data to be written to the (subform) data
table, and add a query command that on dirty for the main form would delete
the children records.

I was hoping for a simple solution.
 
R

Rick Brandt

dsc2bjn said:
If I do as you suggest, the user wouldn't be able to enter any new
(subform)records or update any (subform) records.

My gut is telling me to allow the data to be written to the (subform)
data table, and add a query command that on dirty for the main form
would delete the children records.

I was hoping for a simple solution.

Let both forms save as Access is designed to work and replace your "close
without saving" code with code that deletes the main record. If you have
your relationships set up properly that will also delete the child
record(s).
 
D

dsc2bjn

Deleting the parent and children records works for new entries to the database.

I now need to be able to dump the form and subform changes, if the user
changes their mind on exisiting records. I want to keep the data that was in
the tables before they started editing the record.
 
Ad

Advertisements

C

Clif McIrvin

dsc2bjn said:
Deleting the parent and children records works for new entries to the
database.

I now need to be able to dump the form and subform changes, if the
user
changes their mind on exisiting records. I want to keep the data that
was in
the tables before they started editing the record.

On the form's (and the subform both) Before Update event allow the user
to cancel the update:

(from the help file):
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.Undo
End Sub

[It's a bit more involved than that, but I think you'll get the idea,
since you already have the delete new record concept.]

The thing is, you have to catch a 'cancel' BEFORE the user changes the
focus from form to subform or vicea versa.
 
Ad

Advertisements


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

Top