Canceling record in progress

  • Thread starter Thread starter Sport
  • Start date Start date
S

Sport

What is the best way to just cancel the new record that is in progress,
assuming you are using your own command buttuns.
 
If nothing has happened to cause the record to be saved already, I believe a
SendKeys of two consecutive Esc characters will do what you want in any
language. It is what I use for English-language databases. Some of the
possible drawbacks of using SendKeys are eliminated when it is the
first/only line in the click event of a Command Button. That is, the user
can not have switched applications and have the Esc, Esc apply to the other
application.

If it has already been saved, and there are a number of things which can
cause saving, then it can't be cancelled, but the saved record will have to
be deleted.

Larry Linson
Microsoft Access MVP
 
There is >no way< you can do this 100% reliably in an Access form.

For example, say that one of the fields is Required, and you type a few
characters into that field. Then you change your mind, and click your own
command button, trying to cancel the new record.

The problem is, you >can not< click that command button, until there is a
value in the field in question, or you press Esc once to cancel that field,
or twice to cancel the whole new record.

So in this scenario, you would have to press Esc at least once, before you
could click your command button. In which case, you might just as well press
Esc >twice< to cancel the whole new record, and there is no point >having<
the command button.

HTH,
TC
 
tc is incorrect, i do this all the time.

Create a boolean global variable in the forms class. Call it cance
update(or whatever you want). Set the cancelupdate variable to fals
on the forms open event.

Create a button that will be used to stop the current record from bein
saved (I call my button Exit W/O Save). On the Click event of tha
button set your cancelupdate variable to true and close your for
(docmd.close).

Closing the form causes a new record that is dirty to be saved. When
new record is being saved it first goes to the forms beforeupdat
event. If cancel is set to true during this event the update of th
new record is cancelled. So in this event you simply set cancel
cancelupdate and you exit the form without saving your current record.

The first idea will also work (two esc's), however Microsoft keep
cautioning the use of sendkeys because they intend to get rid of it
 
tc is incorrect, i do this all the time.

Really?

Try this for me.

1. Create a new record;

2. Type something into a mandatory (required) field of that record (but do
not save the record);

3. Go back and overtype that value with spaces;

4. Now try to click your "Exit w/o save" button.

Oops: your button click event >won't fire<.

This proves my statement that there is no way you can code a Cancel button
HTH,
TC
 
Back
Top