about error 3314 (null value)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mseo
    New Member
    • Oct 2009
    • 183

    #1

    about error 3314 (null value)

    hi,
    I am develping a form for adding employees
    I set the controls for firstname, middlename, lastname,hireda te (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

    Code:
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    if an error occurs because of missing data in a required field
    'display our own custom error message
             Const conErrRequiredData = 3314
       If DataErr = conErrRequiredData Then
            MsgBox ("Please ensure that you enter a First Name , Last Name , Middle Name and Hire Date ")
            Response = acDataErrContinue
       Else
        'Display a standard error message
           Response = acDataErrDisplay
       End If
    End Sub
    please help me handling this error
    thanks in advance for any help you may provide me
    Last edited by NeoPa; Nov 1 '09, 11:10 PM. Reason: Please use the [CODE] tags provided.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by mseo
    hi,
    I am develping a form for adding employees
    I set the controls for firstname, middlename, lastname,hireda te (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

    Private Sub Form_Error(Data Err As Integer, Response As Integer)
    if an error occurs because of missing data in a required field
    'display our own custom error message
    Const conErrRequiredD ata = 3314
    If DataErr = conErrRequiredD ata Then
    MsgBox ("Please ensure that you enter a First Name , Last Name , Middle Name and Hire Date ")
    Response = acDataErrContin ue
    Else
    'Display a standard error message
    Response = acDataErrDispla y
    End If
    End Sub

    please help me handling this error
    thanks in advance for any help you may provide me
    A better, and more personalized, approach may be to check for these conditions in the BeforeUpdate() Event of the Form, as in:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If IsNull(Me![firstname]) Then
      MsgBox "You must enter a First Name before this Record can be saved"
        Cancel = True: Me![firstname].SetFocus
    ElseIf IsNull(Me![middlename]) Then
      MsgBox "You must enter a Middle Name before this Record can be saved"
        Cancel = True: Me![middlename].SetFocus
    ElseIf IsNull(Me![lastname]) Then
      MsgBox "You must enter a Last Name before this Record can be saved"
        Cancel = True: Me![lastname].SetFocus
    ElseIf IsNull(Me![hiredate]) Then
      MsgBox "You must enter a Hire Date before this Record can be saved"
        Cancel = True: Me![hiredate].SetFocus
    End If
    End Sub

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      I agree with ADezii; you really have much more control doing this kind of validation in the Form_BeforeUpda te 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)>

      Comment

      • mh90
        New Member
        • Jun 2010
        • 3

        #4
        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!

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          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_BeforeUpda te event.

          Linq ;0)>

          Comment

          • mh90
            New Member
            • Jun 2010
            • 3

            #6
            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_BeforeUpda te. 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?

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              Originally posted by mh90
              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_BeforeUpda te. 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?
              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?

              Comment

              • mh90
                New Member
                • Jun 2010
                • 3

                #8
                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.Compa nyName" cannot contain a Null Value etc." comes back after one clicks ok on the customized message.

                Comment

                Working...