CHANGE MY MIND -- don't write to database

K

kealaz

If I open a form, and start filling it out, but then decide I don't want to
complete what I started and close the form part way thru by clicking on my
"close" command button OR by closing the window using the [X] at the top
right, there is still a record created in my table. How can I prevent this?
Can I add a command button that will allow me to exit from the form without
saving anything?

Thank you very much for your time and help with this!!!
 
J

John W. Vinson

If I open a form, and start filling it out, but then decide I don't want to
complete what I started and close the form part way thru by clicking on my
"close" command button OR by closing the window using the [X] at the top
right, there is still a record created in my table. How can I prevent this?

Can I add a command button that will allow me to exit from the form without
saving anything?

Have the command button execute code like

Private Sub cmdCancel_Click()
Me.Undo
End Sub


Note that neither of these will have the desired effect if you have a form
with subforms, and have setfocus to any subform control: the mainform record
is saved to disk the instant you do so. You'll need some more complexity, such
as a Delete query to explicitly delete the current record from the underlying
table.
 
D

DavisGail

John,
How would you handle exit without saving when there is a form and a subform?

John W. Vinson said:
If I open a form, and start filling it out, but then decide I don't want to
complete what I started and close the form part way thru by clicking on my
"close" command button OR by closing the window using the [X] at the top
right, there is still a record created in my table. How can I prevent this?

Can I add a command button that will allow me to exit from the form without
saving anything?

Have the command button execute code like

Private Sub cmdCancel_Click()
Me.Undo
End Sub


Note that neither of these will have the desired effect if you have a form
with subforms, and have setfocus to any subform control: the mainform record
is saved to disk the instant you do so. You'll need some more complexity, such
as a Delete query to explicitly delete the current record from the underlying
table.
 
J

John W. Vinson

John,
How would you handle exit without saving when there is a form and a subform?

It's too late in that case. That horse is out of the barn and in the next
pasture by now.

The mainform record is saved to disk the moment you set focus to any control
in the subform. Likewise the subform record is saved to disk if you dirty the
subform and then set focus to any mainform control.

The only solution is to actually delete the saved records. As with any
deletion, you need care to ensure that you're only deleting the record (or
records) that you want to delete.
 
D

DavisGail

Thank you.

John W. Vinson said:
It's too late in that case. That horse is out of the barn and in the next
pasture by now.

The mainform record is saved to disk the moment you set focus to any control
in the subform. Likewise the subform record is saved to disk if you dirty the
subform and then set focus to any mainform control.

The only solution is to actually delete the saved records. As with any
deletion, you need care to ensure that you're only deleting the record (or
records) that you want to delete.
 
A

alfaista

Okay, what if I have a form with a subform, but only want to undo changes on
the subform?
My main form is just buttons and some drop downs for filtering a subform.
Need the subform in datasheet view, and main form in form view.

So, when the user makes a change on a row in the subform, my Cancel on the
main form becomes active, but, it doesn't "undo" anything.

Me.subform.Form.Undo
 
J

Jeff Boyce

Could you use an <Undo> button on your subform?

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
J

John W. Vinson

On Wed, 10 Mar 2010 13:31:02 -0800, alfaista


Again:

The instant you set focus to any control on the mainform, whether a command
button or anything else, the subform record is saved to disk and cannot be
"undone", other than by running a Delete Query to delete it.

As Jeff suggests, put an UNDO button on the subform (you may need to use a
Continous Form made to look like a datasheet, if you can't put a button on the
 
A

alfaista

Oh, I see. I didn't think about the user clicking on the button as a setting
focus, but of course it is!! Since I wasn't doing it programatically it
didn't register.

Thanks so much to you both!!
 

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