Error Trapping

G

gaugust

In Access 2003 I would like to trap an error and display a custom error
message when a user forgets to enter the value for a key field on a data
entry form. Currently the user gets the error message "Index or primary key
cannot contain a Null value" when the key field on the form is left blank. I
tried to trap this error in the before update event of the form, the before
update event of the key field and the on error event of the form but the
error occurs and the system message displays before any of these events. How
can I display a custom error message in leu of the system error message?
Thanks.
 
S

strive4peace

the place for record validation is on the form BeforeUpdate event

this sounds, however, like a case where you have a numeric foreign key
in your table that has a Default Value of zero (Access automatically
assigns this for numeric fields) -- delete the Default Value for numeric
foreign key fields in the table design

Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
G

gaugust

I checked and there are no default values of zero in any foreign keys. I
tried to place the record validation in the BeforeUpdate event of the key
field and the form but the system error still appears.
 
B

Beetle

My first question would be why are you letting users even have access to, not
to mention control of, Primary or Foreign Key fields in your application?
These
values should be automatically inserted by the application every time a new
record is created. If you are not using Autonumber for your PK, there is
usually
a way to use code to automatically generate new values.
 

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

Similar Threads

Access 2007 ODBC Error Trapping 8
Catch Error 3
Why don't I get an error message? 9
Index or Primary Key Cannot Have A Null Value 4
error trapping 3
handling error 3
Error Message Trapping 1
Trapping Error 3101 5

Top