How to cancel info on a form?

A

Amit

Hi,

My client would like to have two buttons for new
information being filled out on a form - "Save"
and "Cancel". I'm all set with the "Save" button and the
code. Not so sure how to code the "Cancel" button.

Would it be:
-Me.Dirty = True
-frmClose?

Basically, if the person fills out the information on the
form, and then decides not to save that information, s/he
would click the "Cancel" button.

Thanks for any pointers/help.

-amit
 
A

Adrian Jansen

Or you can use me.undo which erases all the current entries on the form, as
a slightly better feedback to the operator, then the form close.

--
Regards,

Adrian Jansen
J & K MicroSystems
Microcomputer solutions for industrial control
 
S

Sandra Daigle

Try:

me.undo

then if you also want to close the form:

docmd.close acform, me.name
 
G

Graham Mandeno

Hi Amit

The operation to cancel an update is Me.Undo:
If Me.Dirty Then Me.Undo
This will also reset Me.Dirty to False.

However, you need to be careful, because the default action when you move to
a new record, or when you close the form, is to save a dirty record. What I
do is declare a module-level variable:
Dim fSaving As Boolean

Then cmdSave_Click procedure sets this to True and saves the record, while
Form_Current sets it to False. Form_BeforeUpdate checks its value, and if
it is NOT True, then it knows the Save button has not been clicked, and the
record is being "automatically" saved. You can ask (with a Yes/No/Cancel
msgbox) if the user wants to save the changed record.
 

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