program a cancel button

  • Thread starter Thread starter mike
  • Start date Start date
M

mike

Hi all,

How do I program a command button to cancel an add
entries. I used the access wizard to create a add record
and the code is:

DoCmd.GoToRecord , , acNewRec

Can I program a command button to cancel the add record
entry? If possible, How??

Thanks for the help..

mike
 
If to form does not contain a subform .. all you need to to use:

Me.Undo

That will Cancel an uncommitted record.

RDH
 
The Esc key will do this. The first time you press it you cancel the current field, the
second time you cancel all changes to the current record. To do this in code you would use

Me.ctrControlName.Undo for the 1st option and
Me.Undo for the 2nd option

There is no need to use both at once, Me.Undo will work first time.
 
My from contains subform, will code work for subform??

mike
-----Original Message-----
If to form does not contain a subform .. all you need to to use:

Me.Undo

That will Cancel an uncommitted record.

RDH



------------------------------------------------
 
Once you navigate from the mainform to the subform .. the record for th
mainform will be saved the table ....

The only recourse would be to delete the mainform record.

RD
 
Despite what some of the others have said, there is no way to program a
100% reliable "cancel changes" button in MS Access.

For example, say you start entering data into a required field of a new
record. Say you change your mind, and erase that data, in an attempt to
cancel the new record. Access will object to the missing mandatory field.
Say that you now click your Cancel button. Access can not fire the Click
event of that button, until it has moved the focus (cursor) away from the
missing mandatiory field; but it can not move the focus away from that
field, until a value has been typed in it! Catch 22. The only way to cancel
that unsaved new record, is to press the Escape key a few times.

This problem is avoided by certain other development products (eg. Oracle
forms), which let you define a button that >does not< try to grab the focus
when you click that button. Thus, the button click event can fire, even
though the focus is still in the missing required field. But that is not a
feature of Access forms.

HTH,
TC
 
Good point TC,

What you mention is why I tend to enforce required fields in the Form's BeforeUpdate event
instead of in the table design. It would be nice though to have a button that doesn't grab
the focus as you have mentioned.
 
Back
Top