Duplicate values in index message

R

Rick in N S

In table tblPhones I have an unique index consisting of:

ContactID PK autonumber
PhoneType Text (ie Home; Work; Cell; Mobile; Cottage; etc)

to prevent users from recording duplicate phone types.

When they do attempt to use a phone type the second time
they get the standard Access message:

"The changes you requested to the table were not
successful because they would create duplicate values in
the index, primary key, or relationship. Change the data
in the field for fields that contain duplicate data,
remove the index, or redefine the index to permit
duplicate entries and try again."

How do prevent this standard message message from
appearing and replace it with a less ambigous one such
as "You have already recorded this phone type for this
contact."
 
B

Brian

Rick in N S said:
In table tblPhones I have an unique index consisting of:

ContactID PK autonumber
PhoneType Text (ie Home; Work; Cell; Mobile; Cottage; etc)

to prevent users from recording duplicate phone types.

When they do attempt to use a phone type the second time
they get the standard Access message:

"The changes you requested to the table were not
successful because they would create duplicate values in
the index, primary key, or relationship. Change the data
in the field for fields that contain duplicate data,
remove the index, or redefine the index to permit
duplicate entries and try again."

How do prevent this standard message message from
appearing and replace it with a less ambigous one such
as "You have already recorded this phone type for this
contact."

You can trap the error in the form's Error event. It's error number 3022.
 
R

Rick in N S

Thanks Brian. Curious; how were you able to determine it
is error # 3022?

I tried getting the error number by using an error event
but it did not fire as expected. The standard message
kept coming up without any reference to the error number
of course.
 
B

Brian

Rick in N S said:
Thanks Brian. Curious; how were you able to determine it
is error # 3022?

I tried getting the error number by using an error event
but it did not fire as expected. The standard message
kept coming up without any reference to the error number
of course.

After many years of working with Access, there are some error numbers I know
by heart!

However, in the form's Error event, it's in the DataErr argument. If your
form's Error event is not firing, check in the form's properties window
(events tab) that it reads "[Event Procedure]" against the On Error event.
 
R

Rick in N S

Thanks Brian, most helpful! Final question. I am able to
display the error number in a msgbox as follows:

MsgBox "The error is " & DataErr

Is there any way to display the error description along
with the error number?




-----Original Message-----

Thanks Brian. Curious; how were you able to determine it
is error # 3022?

I tried getting the error number by using an error event
but it did not fire as expected. The standard message
kept coming up without any reference to the error number
of course.

After many years of working with Access, there are some error numbers I know
by heart!

However, in the form's Error event, it's in the DataErr argument. If your
form's Error event is not firing, check in the form's properties window
(events tab) that it reads "[Event Procedure]" against the On Error event.


.
 
B

Brian

Rick in N S said:
Thanks Brian, most helpful! Final question. I am able to
display the error number in a msgbox as follows:

MsgBox "The error is " & DataErr

Is there any way to display the error description along
with the error number?

accesserror(DataErr)
 

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