How to cancel info on a form?

  • Thread starter Thread starter Amit
  • Start date Start date
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
 
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
 
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.
 
Back
Top