new vs. old record

  • Thread starter leahf via AccessMonster.com
  • Start date
L

leahf via AccessMonster.com

A student record includes a social security number.

If the number entered does not meet the requirements, the user is asked if
he/she wants to change the number.

If the user answers yes, and the student is a new one, the script includes
cancel=true
and then set focus to the field so that the number can be corrected.
That is fine.

However, if the student data is being updated, and the user wants to correct
the field, using cancel=true and focusing on the field does not work. The
user is exited to the previous screen.

What is the difference between a new student being entered and updating an
existing one?

Thanks.
Leah
 
R

Rick Brandt

leahf said:
A student record includes a social security number.

If the number entered does not meet the requirements, the user is asked if
he/she wants to change the number.

If the user answers yes, and the student is a new one, the script includes
cancel=true
and then set focus to the field so that the number can be corrected.
That is fine.

However, if the student data is being updated, and the user wants to correct
the field, using cancel=true and focusing on the field does not work. The
user is exited to the previous screen.

What is the difference between a new student being entered and updating an
existing one?

What is your code and what event are you using?

Normally validation like this goes into the BeforeUpdate event of the
control. In that event all you need to do when validation fails is to
set Cancel=True. There is no need to set focus because the control
being changed never loses focus.
 
L

leahf via AccessMonster.com

Hi,

I had it at the control field but there were problems so I decided to check
the field at the BeforeUpdate event of the form.

If no correction is done (new or old form) there is no problem.

A correction on a new form is fine.

A correction on an old form gives no error, but just exits. I am trying to
not exit the form.

I have tried:
Cancel = True
StudentIdNum.SetFocus

I have also tried:
Undo

And:
DoCmd.CancelEvent

Each time it exits and goes to the previous screen which lists all the
students.

Truthfully, I don't remember the problems when I was checking all this at the
field BeforeUpdate. Isn't there a way to prevent the Access from continuing
to the next event?

Thanks.
Leah


Rick said:
A student record includes a social security number.
[quoted text clipped - 12 lines]
What is the difference between a new student being entered and updating an
existing one?

What is your code and what event are you using?

Normally validation like this goes into the BeforeUpdate event of the
control. In that event all you need to do when validation fails is to
set Cancel=True. There is no need to set focus because the control
being changed never loses focus.
 
R

Rick Brandt

leahf said:
I had it at the control field but there were problems so I decided to check
the field at the BeforeUpdate event of the form.

If no correction is done (new or old form) there is no problem.

A correction on a new form is fine.

A correction on an old form gives no error, but just exits. I am trying to
not exit the form.

I have tried:
Cancel = True
StudentIdNum.SetFocus

I have also tried:
Undo

And:
DoCmd.CancelEvent

Each time it exits and goes to the previous screen which lists all the
students.

Truthfully, I don't remember the problems when I was checking all this at the
field BeforeUpdate. Isn't there a way to prevent the Access from continuing
to the next event?

Are you allowing a normal event (closing the form or navigating) to
induce the saving of the record or do you have a [Save] button? When
you have a block of code like...

(code to save record)
(code to close form)

....and use Cancel in the BeforeUpdate all you are doing is cancelling
the save. The next line that closes the form still happens. Could
something like that be what you are seeing?

For cases like that you have to do your validation in your code and only
run the save and close code when validation is good. You cannot rely on
cancelling events.
 
L

leahf via AccessMonster.com

There is an exit button.

Okay. Thank you. Now I see that I have to change the code from the exit
button so that it does not automatically close the form.

Thanks so much.

Leah

Rick said:
I had it at the control field but there were problems so I decided to check
the field at the BeforeUpdate event of the form.
[quoted text clipped - 22 lines]
field BeforeUpdate. Isn't there a way to prevent the Access from continuing
to the next event?

Are you allowing a normal event (closing the form or navigating) to
induce the saving of the record or do you have a [Save] button? When
you have a block of code like...

(code to save record)
(code to close form)

...and use Cancel in the BeforeUpdate all you are doing is cancelling
the save. The next line that closes the form still happens. Could
something like that be what you are seeing?

For cases like that you have to do your validation in your code and only
run the save and close code when validation is good. You cannot rely on
cancelling events.
 

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