Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Message 1

Status
Not open for further replies.

supervi

MIS
Mar 22, 2003
61
CA
I have a field which is my primary key. If that field is blank and i try and click save record it gives me an error saying that index or primary key can't contain null value.

My question is how do i change that error to say something like "Please complete the ticket number field"

Where in the code would i go. I tried flipping through the code and i have tons of err.descriptions.

Thanks
 
You will probably need to write some code to do this. It will need to be controlled by all of the events that can cause Access to try to save the current record on the form. I would think the On Current for sure, and certainly some others as well. First, I would have the code turn off Access' message processing, then display my custom message in a message box. Then turn on Access' message processing.

Frank kegley
fkegley@hotmail.com
 
Sorry if this is a stupid question but how exactly would one go about turning off "access message processing"
 
I think what fkegley means to suggest is to turn warnings on and off....

DoCmd.SetWarnings False (turns warnings off)
DoCmd.SetWarnings True (turns warnings on)

I would leave the error handler as is but replace the current message (err.description) with my own message box.
 
I was able to fix it for the save button. All i did was change

MsgBox Err.Description
to

Msgbox "You didnt fill out the ticket field"

When i click into my subform and the primary key field is blank, I get the same message index or primary key can't contain null value

Anyone know where that message would be located in the code? So that I can change it

Thanks
 
Hi!

This isn't a run time error, nor the "query" message thingie, it's what's referred to as a form error, and can be "trapped" thru using the form error event. If I'm not mistaken, I think the primary key violation (dupes) is DataErr = 3022, then something like this might apply in the forms on error event:

[tt]private sub form_error(dataerr as integer, response as integer)
if dataerr = 3022 then
msgbox "Please complete the ticket number field"
response = acdataerrcontinue
end if
end sub[/tt]

- should it be another error, try msgbox dataerr to retrieve it

Roy-Vidar
 
Roy your a genius

The exact number was 3058 but your method worked perfectly

If dataerr = 3058 Then
MsgBox "Please enter a Deal Ticket Number"
response = acDataErrContinue
End If

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top