469,950 Members | 1,946 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

about error 3314 (null value)

181 100+
I am develping a form for adding employees
I set the controls for firstname, middlename, lastname,hiredate (Is Not Null) in the table.
but in the form when I don't insert any field of those fields I definetly will get error number 3314 because I didn't insert the required fields
so I just want to write my custom message when I click save to be viewed for the user or at least when the user doesn't insert the required field
I used this code but it doesn't work as I want

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Error(DataErr As Integer, Response As Integer)
  2. if an error occurs because of missing data in a required field
  3. 'display our own custom error message
  4.          Const conErrRequiredData = 3314
  5.    If DataErr = conErrRequiredData Then
  6.         MsgBox ("Please ensure that you enter a First Name , Last Name , Middle Name and Hire Date ")
  7.         Response = acDataErrContinue
  8.    Else
  9.     'Display a standard error message
  10.        Response = acDataErrDisplay
  11.    End If
  12. End Sub
please help me handling this error
thanks in advance for any help you may provide me
Oct 31 '09 #1
7 12081
8,800 Expert 8TB
A better, and more personalized, approach may be to check for these conditions in the BeforeUpdate() Event of the Form, as in:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If IsNull(Me![firstname]) Then
  3.   MsgBox "You must enter a First Name before this Record can be saved"
  4.     Cancel = True: Me![firstname].SetFocus
  5. ElseIf IsNull(Me![middlename]) Then
  6.   MsgBox "You must enter a Middle Name before this Record can be saved"
  7.     Cancel = True: Me![middlename].SetFocus
  8. ElseIf IsNull(Me![lastname]) Then
  9.   MsgBox "You must enter a Last Name before this Record can be saved"
  10.     Cancel = True: Me![lastname].SetFocus
  11. ElseIf IsNull(Me![hiredate]) Then
  12.   MsgBox "You must enter a Hire Date before this Record can be saved"
  13.     Cancel = True: Me![hiredate].SetFocus
  14. End If
  15. End Sub
Oct 31 '09 #2
3,532 Expert 2GB
I agree with ADezii; you really have much more control doing this kind of validation in the Form_BeforeUpdate event.

Also, please remember, when posting code, to use code tags, as it makes it much easier for those trying to help you to read it. It's really easy to do.
  1. Click on "Go Advanced"
  2. Hilight your code
  3. Click on the pound sign (#) in the tool bar
Linq ;0)>
Oct 31 '09 #3
Hi, I've applied the solution which is great, but I get a "No Record" error. Is there something I can do about that?

Thanks for any help!
Jun 2 '10 #4
3,532 Expert 2GB
This is very strange! Where did place your code? If it's in the Form_Before event, as ADezii's example shows, there really has to be a record! Otherwise Access wouldn't go to the Form_BeforeUpdate event.

Linq ;0)>
Jun 2 '10 #5
Whoops, I guess the preview button is there for a reason!

I meant to say, it returns a "No current record" error.

I did put it in the Form_BeforeUpdate. However, my scenario is that the user is entering a completely new record (the form always opens in Add Mode there are no navigation tools to see previous records). Does that have anything to do with the error?
Jun 2 '10 #6
8,800 Expert 8TB
Should have nothing to do with the Error at all. Is there other code running in this Event or in the Current() Event of the Form?
Jun 2 '10 #7
Nope, there are no other codes.

I've narrowed it down to this. If I remove the lines that have "Cancel = True: Me![firstname].SetFocus"
Then the "No current record" error goes away. But the original "The field "Customer.CompanyName" cannot contain a Null Value etc." comes back after one clicks ok on the customized message.
Jun 2 '10 #8

Post your reply

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

Similar topics

3 posts views Thread by WindAndWaves | last post: by
2 posts views Thread by Bill Stock | last post: by
1 post views Thread by Jeremy Ames | last post: by
7 posts views Thread by Adrian Parker | last post: by
11 posts views Thread by hammad.awan_nospam | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.