How deal with button to goto a new record

M

mscertified

I have an OnClick event that does:
DoCmd.GoToRecord , , acNewRec
My problem is that this fires the BeforeUpdate event which does some
validations and can issue 'Cancel = True'
Then my OnClick event fails with "Can't go to specified record"

The only thing I can think of is to do all the validations before I do the
'Docmd.GoToRecord' but then they will be done twice.

Am I doing this completely wrong? I did not write this code but I'd like it
to work properly.
 
D

Dennis

I dunno what the other guys will say, but ONE METHOD would be to set a PUBLIC
Boolean variable to TRUE in the ONCLICK event for the button, immediately
before executing the DOCMD. Then, in the BEFOREUPDATE event, check to see if
the Boolean is TRUE. If yes, set to FALSE and do an EXIT SUB before any of
the validation code gets executed.
 
B

Bob Quintal

It is a good concept, but no need to set a public variable, just
define the variable in the declarations section of the form's
module. Set it to true or false dependent on the validation
result in the beforeUpdate event and test for its state in the
OnClick event.

Q

I dunno what the other guys will say, but ONE METHOD would be
to set a PUBLIC Boolean variable to TRUE in the ONCLICK event
for the button, immediately before executing the DOCMD. Then,
in the BEFOREUPDATE event, check to see if the Boolean is
TRUE. If yes, set to FALSE and do an EXIT SUB before any of
the validation code gets executed.
 
F

fredg

I have an OnClick event that does:
DoCmd.GoToRecord , , acNewRec
My problem is that this fires the BeforeUpdate event which does some
validations and can issue 'Cancel = True'
Then my OnClick event fails with "Can't go to specified record"

The only thing I can think of is to do all the validations before I do the
'Docmd.GoToRecord' but then they will be done twice.

Am I doing this completely wrong? I did not write this code but I'd like it
to work properly.

Remove the GotoRecord from the BeforeUpdate event.
Place it in the AfterUpdate event.
 
M

mscertified

It's not in the BeforeUpdate event, it's in the OnClick event for the button.
The validation code is in the BeforeUpdate event.
 
S

Scott McDaniel

I have an OnClick event that does:
DoCmd.GoToRecord , , acNewRec
My problem is that this fires the BeforeUpdate event which does some
validations and can issue 'Cancel = True'
Then my OnClick event fails with "Can't go to specified record"

The only thing I can think of is to do all the validations before I do the
'Docmd.GoToRecord' but then they will be done twice.

Am I doing this completely wrong? I did not write this code but I'd like it
to work properly.

Or try this:

'/save the data, if possible
If Me.Dirty Then Me.dirty = False
'/now check again
If Not Me.Dirty Then DoCmd.GoToRecord,,acNewRec

So you attempt to save the data ... if this succeeds, then the Dirty property will be false, and you can then go to your
new record

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 

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