Changing default key violation message?

H

Howard

Can this be done?

How would I trap the error and present a more freindly message like "You
cannot have two cars with the same registration number" rather than the
complex, non user freindly message that access gives me.

Howard
 
J

Jeff Boyce

Howard

You could add error handling to your code, intercept the error number, and
create/display your own message.

You could add code to the RegistrationNumber field's BeforeUpdate event that
checks for the situation and prevents it, rather than allowing a user to
fill in a form and THEN telling him/her that they couldn't do that ("start
over, you made a mistake back up in line 7"). You'd add your message in
that BeforeUpdate routine, and set Cancel = True to not accept the
duplicated registration number.
 
H

Howard

Thank you Jeff,

I presume I could check for the situation using something like the following

If DCount("*","[Cars]","[CarReg]=" & Me!CarReg) >= 0 Then
MsgBox "This car already exists", vbOKOnly
Cancel = True
end if

Howard
 
J

Jeff Boyce

Howard

What you've proposed requires Access to use a (somewhat) slower function
("DCount()"). But hey! whatever works! Have you tested your code?

--
Good luck

Jeff Boyce
<Access MVP>

Howard said:
Thank you Jeff,

I presume I could check for the situation using something like the following

If DCount("*","[Cars]","[CarReg]=" & Me!CarReg) >= 0 Then
MsgBox "This car already exists", vbOKOnly
Cancel = True
end if

Howard

Jeff Boyce said:
Howard

You could add error handling to your code, intercept the error number, and
create/display your own message.

You could add code to the RegistrationNumber field's BeforeUpdate event
that
checks for the situation and prevents it, rather than allowing a user to
fill in a form and THEN telling him/her that they couldn't do that ("start
over, you made a mistake back up in line 7"). You'd add your message in
that BeforeUpdate routine, and set Cancel = True to not accept the
duplicated registration number.

--
Good luck

Jeff Boyce
<Access MVP>
 
H

Howard

Yes, that seems to work, but I needed to put in a docmd.undo as well as the
record was being saved as soon as I lost focus on that field - thus makingit
even slower!. Seems ok now though, thanks Jeff

Howard

Jeff Boyce said:
Howard

What you've proposed requires Access to use a (somewhat) slower function
("DCount()"). But hey! whatever works! Have you tested your code?

--
Good luck

Jeff Boyce
<Access MVP>

Howard said:
Thank you Jeff,

I presume I could check for the situation using something like the following

If DCount("*","[Cars]","[CarReg]=" & Me!CarReg) >= 0 Then
MsgBox "This car already exists", vbOKOnly
Cancel = True
end if

Howard

message
Howard

You could add error handling to your code, intercept the error number, and
create/display your own message.

You could add code to the RegistrationNumber field's BeforeUpdate event
that
checks for the situation and prevents it, rather than allowing a user
to
fill in a form and THEN telling him/her that they couldn't do that ("start
over, you made a mistake back up in line 7"). You'd add your message
in
that BeforeUpdate routine, and set Cancel = True to not accept the
duplicated registration number.

--
Good luck

Jeff Boyce
<Access MVP>

Can this be done?

How would I trap the error and present a more freindly message like "You
cannot have two cars with the same registration number" rather than
the
complex, non user freindly message that access gives me.

Howard
 

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