Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Manassas, Virginia, USA
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Prevent display of Access error message (2002, SP 3)

    I have an error message I want to display if a user tries to leave a record without entering a key value. I placed the code (to display my error message and then to set the focus to that field) in the On Error event for my form and it brings up my message but then it also displays the Access error message "Index or primary key can not contain a null value." How can I prevent the Access message.
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Prevent display of Access error message (2002, SP 3)

    The On Error event procedure has an argument Response. Its default value is acDataErrDisplay, which means that Access will display the built-in error message. If you want to suppress this message, set Response to acDataErrContinue. Here is an example:

    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Select Case DataErr
    Case 3058
    ' Display custom message
    MsgBox "Thou shalt not leave a key field blank!", vbExclamation
    ' Suppress built-in message
    Response = acDataErrContinue
    Case Else
    ' Display the built-in message
    Response = acDataErrDisplay
    End Select
    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    Manassas, Virginia, USA
    Posts
    363
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prevent display of Access error message (2002, SP 3)

    Thank you. That worked perfectly. I'll add that to my bag of tricks.
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •