Confused about the 'Cancel' argument

  • Thread starter Thread starter rsosabusiness
  • Start date Start date
R

rsosabusiness

I have a form with navigation buttons and also a command button which I
want to control all the record updates (OK button). In the BeforeUpdate
event for the form I tested to see if I had arrived there by clicking
one of the navigation buttons. If I did, I would set the 'Cancel'
argument to true on the assumption that the update would be canceled
and the record would stay put until it was updated with the 'OK'
button. This caused the error ' you cannot go to the specified record'
(or close to that). How can I accomplish what I described without
causing the error?
Cordially,
Robert
 
Before Access can move to another record, it must save the current one if it
is dirty. If you cancel Form_BeforeUpdate, then it cannot save the record.
If follows that if you cancel Form_BeforeUpdate, you are indeed preventing
it from moving to another record, and that situation is logically not
avoidable.
 
I have a form with navigation buttons and also a command button which
I want to control all the record updates (OK button). In the
BeforeUpdate event for the form I tested to see if I had arrived
there by clicking one of the navigation buttons. If I did, I would
set the 'Cancel' argument to true on the assumption that the update
would be canceled and the record would stay put until it was updated
with the 'OK' button. This caused the error ' you cannot go to the
specified record' (or close to that). How can I accomplish what I
described without causing the error?
Cordially,
Robert

In your navigation button code just test the Dirty property of the form. When
True you know that an update will happen if you allow the navigation to occur.
So when Dirty = True just DON'T execute the navigate statement.

BTW have you taken into account the various other ways one can trigger a
navigation or record save in Access?

Apply a filter
Remove a filter
<Shift + Enter>
Close the form
Various menu and toolbar options

In general it is not a good idea to try to control how and when Access saves a
record. What you should do is to set up required fields, validation rules,
unique indexes and foreign constraints in the table design so that only a good
record can be saved (regardless of the mechanism that triggers the save). This
can be augmented by running code in BeforeUpdate of your form that sets Cancel =
True when the record doesn't satisfy your requirements, but when doing that you
should not care what triggered the save attempt.

The only way to have TOTAL control of the save is to use unbound forms, but then
you sacrifice an awful lot of the features that Access provides.
 
In your navigation button code just test the Dirty property of the form. When
True you know that an update will happen if you allow the navigation to occur.
So when Dirty = True just DON'T execute the navigate statement.

BTW have you taken into account the various other ways one can trigger a
navigation or record save in Access?

Apply a filter
Remove a filter
<Shift + Enter>
Close the form
Various menu and toolbar options

In general it is not a good idea to try to control how and when Access saves a
record. What you should do is to set up required fields, validation rules,
unique indexes and foreign constraints in the table design so that only a good
record can be saved (regardless of the mechanism that triggers the save). This
can be augmented by running code in BeforeUpdate of your form that sets Cancel =
True when the record doesn't satisfy your requirements, but when doing that you
should not care what triggered the save attempt.
Thank you Allen and Rick. Your suggestions are tremendeously helpful.
Cordially,
Robert
 
Back
Top