subform and cancel button?

J

jen

I have been working on this issue for hours. I have a
main form and a subform. There is a cancel button on the
main form. The cancel process does not work correctly if
the user changes something on the subform OR if the user
changes something on the main form and subform. The
changed values on the subform are saved and shouldn't be
(since user hit cancel). this is what i have in my
cancel_click:

me.controls.item("frmMain").setfocus
docmd.domenuitem acFormBar, acEditMenu, asUndo, ,
acMenuVer70
me.controls.item("frmSubform").setfocus
docmd.domenuitem acFormBar, acEditMenu, asUndo, ,
acMenuVer70

Does anyone have any ideas?.. this is driving me crazy..
spending so m uch time on this.. any help is very much
appreciated! thanks.
 
J

John Vinson

I have been working on this issue for hours. I have a
main form and a subform. There is a cancel button on the
main form. The cancel process does not work correctly if
the user changes something on the subform OR if the user
changes something on the main form and subform. The
changed values on the subform are saved and shouldn't be
(since user hit cancel). this is what i have in my
cancel_click:

me.controls.item("frmMain").setfocus
docmd.domenuitem acFormBar, acEditMenu, asUndo, ,
acMenuVer70
me.controls.item("frmSubform").setfocus
docmd.domenuitem acFormBar, acEditMenu, asUndo, ,
acMenuVer70

Does anyone have any ideas?.. this is driving me crazy..
spending so m uch time on this.. any help is very much
appreciated! thanks.

Access saves the mainform record to disk the moment you set focus to
the subform, making Undo ineffectual; it's too late, the record is
already written. Similarly each record on the subform is written to
disk as you move to a new record, or back to the mainform.

In order to remove these records, you must actually run a Delete query
deleting the records from the mainform's and subform's tables. The
Undo method simply won't work.


John W. Vinson[MVP]
 
G

Guest

thank you for the reply.. but if the user was editing a record(s) - (my
subform is a continious form) and then decided to cancel.. i would not want
to delete the record(s).. can you explain abit more please.. any more advice
 
J

John Vinson

thank you for the reply.. but if the user was editing a record(s) - (my
subform is a continious form) and then decided to cancel.. i would not want
to delete the record(s).. can you explain abit more please.. any more advice
on my situation? thanks so much!

Just what are you "cancelling"?

Scenario:

User enters a record on the mainform.
User moves to the subform. (Access saves the mainform record to disk,
adding it to the table, making Undo useless for that record).
User enters eight records on the subform. (Access saves each one to
disk when the user moves to the next record, making Undo useless for
those record too).
User clicks the Cancel button.

What do you want to "cancel"? That eighth record? All eight records
and the mainform record? or what?

John W. Vinson[MVP]
 
G

Guest

Well i have 2 different situations for 2 different forms (each having a
continnious subform).. if the user were on my "new" entry form.. i would want
everything (mainform and the 8 records) cancelled. If they were on my "edit"
entry form i would want whatever they changed cancelled.. if that be changes
on the main form and/or the subform.

thanks.
 
G

Guest

aah.. ok so i understand the deleting you mentioned (this should work on my
"new' entry forms).. but have any ideas for my 'edit' entry form? thanks!
 
J

John Vinson

Well i have 2 different situations for 2 different forms (each having a
continnious subform).. if the user were on my "new" entry form.. i would want
everything (mainform and the 8 records) cancelled.

Then you must run two Delete queries; or set the relationship between
the tables to Cascade Deletes, and run a delete query to delete the
main table record.
If they were on my "edit"
entry form i would want whatever they changed cancelled.. if that be changes
on the main form and/or the subform.

You can only cancel changes on one record at a time. Again - the Form
is not where the data is stored! Just because several records are
visible on the Form, you can't assume that that is "temporary"
information; all but the one record which is currently being edited
(on the mainform or the subform) is already permanently and
un-cancellably stored in the Table, and the only way to erase it is to
delete it form the table. Changes in the values of the fields cannot
be undone at all, unless you (using VBA code) keep a log of all field
changes.

John W. Vinson[MVP]
 
J

John Vinson

aah.. ok so i understand the deleting you mentioned (this should work on my
"new' entry forms).. but have any ideas for my 'edit' entry form? thanks!

If you want to be able to "undo" edits to the mainform record and an
arbitrary number of subform records...

YOU CAN'T.

The only way you would be able to do this is to bind your Form and
Subform to temporary tables, and have some facility to copy the data
from the temporary tables into the "real" tables.

You have to make *some* cutoff as to when data is "accepted". Unless
you keep a log of every change, to every field, forever - or use
SQL/Server with transaction rollbacks and database logs - you need to
train your users that when they enter data into the table, they're
entering data into the table, and it's extra work if they change their
mind.

John W. Vinson[MVP]
 
G

Guest

Thanks for all of your help. My previous post, the one where i said i
understand the delete process and that it should work for my 'new' entry form
and then i asked you if you had any ideas for my 'edit' form.. that post.. i
actually wrote before i read your post explaining to me, the first time,
about it not being possible.. unless i track all the changes, etc... sorry.
but again.. thanks for all your help.. i have a much better understanding of
it all now.
 

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