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

    Error code (Access 2002)

    What is the error code number for a duplicate entry into the key field. I would like to trap this error so I can have my own error message appear instead of the one automatically generated by Access.
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error code (Access 2002)

    From the help file :
    The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. (Error 3022)
    Francois

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

    Re: Error code (Access 2002)

    Hi Judy,

    The error number is 3022. You can trap it by creating an On Error event procedure for the form as a whole:

    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    Select Case DataErr
    Case 3022 ' Duplicate key value
    ' Your error message here, for example:
    MsgBox "The ID field cannot contain duplicate values.", vbExclamation
    ' Tell Access to suppress the built-in error message
    Response = acDataErrContinue
    Case Else
    ' Display the built-in error message
    Response = acDataErrDisplay
    End Select
    End Sub

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

    Re: Error code (Access 2002)

    I realized after trying this that the duplication is not based on a key field but rather on a unique indexed field combination. Would the code number be different to trap for duplication of a unique index vs duplication of a key field?
    Judy Jones, Computer Training Specialist
    Manassas, Virginia

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

    Re: Error code (Access 2002)

    No, that doesn't matter. From the error message text:
    <hr>The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship.<hr>
    The same error occurs whether you have a unique index on one field or on the combination of several fields. It doesn't matter whether it's the primary key or not.

Posting Permissions

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