How to trap "Index or primary key canot contain a null value"

p0welly

Registered User.
Local time
Today, 12:51
Joined
Aug 26, 2004
Messages
38
I have a form with a data sheet that allows information to be keyed into a table, this table has a primary key that must be filled in. if you dont, you get the error message "Index or primary key cannon contain a null value"

How can I trap this error and replace the message with something more friendly?

Ive tried the on error event but this just displays my message before the access one
 
How about a field valdation before the record gets saved?
If FIELD ="" then
'show message
'set focus back to field
End IF

?
Your user should never be able to get to save the record if required items are not filled in.
 
Excellent Thanks for pointing me in the right direction, I ended up with the following on the before update.

Code:
if isnull(category) then
Msgbox "you must enter a category"
mycancelbuttonpressed = true
else
mycancelbuttonpressed = false
end if

if mycancelbuttonpressed = true then
cancel = true
exit sub
end if

the mycancelbuttonpressed bit was also found on here
 
What if the field contains an empty string? User starts to key something then they remove it... It is now empty but no longer null.

Code:
If IsNull(txtCategory) or txtCategory = "" Then
 
What if the field contains an empty string? User starts to key something then they remove it... It is now empty but no longer null.

If a user starts to key something then they remove it... It is now null.

It is a zero-length string only if the user specifically keyed "".

^
 

Users who are viewing this thread

Back
Top Bottom