By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,476 Members | 889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,476 IT Pros & Developers. It's quick & easy.

Change primary key error message ms access

Nathan H
100+
P: 104
I get the standard message on a form when a new record is created without supplying a new or valid primary key. Where can I put the On Error code so it will override the generic "Primary Key Can Not Contain a Null Value" and replace it with more detailed instructions.
Dec 19 '07 #1
Share this Question
Share on Google+
4 Replies


puppydogbuddy
Expert 100+
P: 1,923
I get the standard message on a form when a new record is created without supplying a new or valid primary key. Where can I put the On Error code so it will override the generic "Primary Key Can Not Contain a Null Value" and replace it with more detailed instructions.
Hi Nathan,
If it is a trapable error, you can intercept it and display a custom message using the Form_Error event. See this link for a step by step:

http://www.databasedev.co.uk/custom-error-message.html
Dec 19 '07 #2

Nathan H
100+
P: 104
Hi Nathan,
If it is a trapable error, you can intercept it and display a custom message using the Form_Error event. See this link for a step by step:

http://www.databasedev.co.uk/custom-error-message.html
Hi pdb,

Yeah, the form error property works, but then is instantly followed by the standard "Primary Key/Null Value" message box.

I need to find a way to suppress that message, and then the form error property will due fine...

Nathan
Dec 19 '07 #3

puppydogbuddy
Expert 100+
P: 1,923
Hi pdb,

Yeah, the form error property works, but then is instantly followed by the standard "Primary Key/Null Value" message box.

I need to find a way to suppress that message, and then the form error property will due fine...

Nathan
Nathan,
If the error is a trapable error, issuing the Response = acDataErrContinue after you have trapped it and displayed your custom message is supposed to suppress the standard message. You followed the instructions in the link? And it is not working?? Can you post your code?
Expand|Select|Wrap|Line Numbers
  1. If DataErr = conErrRequiredData Then
  2.         MsgBox ("Please ensure that you enter a First Name and Last Name")
  3.         Response = acDataErrContinue
  4.     Else
  5.         'Display a standard error message
  6.         Response = acdatadisplay
  7.     End If
Dec 19 '07 #4

Nathan H
100+
P: 104
Got it now. for some reason I was getting an Error 3023 on the trap....after compacting the db I then got the correct Error 3058. Code works fine now:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Error(DataErr As Integer, Response As Integer)
  2.  
  3. 'If an error occurs because of missing data in a required field
  4. 'display our own custom error message
  5.  
  6.     Const conErrRequiredData = 3058
  7.  
  8.     If DataErr = conErrRequiredData Then
  9.         MsgBox ("Please add an author id to each new author entry")
  10.         Response = acDataErrContinue
  11.     Else
  12.         'Display a standard error message
  13.         Response = acdatadisplay
  14.     End If
  15. End Sub
Dec 19 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.