Help Please!! - Append query throw Key Violation Error

Darren 0 Reputation points
2026-10-02T18:49:45.24+00:00

I have an append query appending records to the table (tblIntake) and I am getting a key violation error and I am trying to figure out why is is throwing a key violation error. I do not write any values to the primary key (IntakeID).

I have done the following so far:

  1. Checked for duplicate primary key values - none in the table tblIntake
  2. Checked for duplicate values in any unique indexes (only the one unique index IntakeID)
  3. Checked to confirm I am not trying to write any value to the primary key (IntakeID)
  4. Checked for any duplicate records in the append query itself. The query is only append one record at a time.
  5. Check for any existing relationships in the database. None show when I use the "Relationships" option on the Database Tools ribbon.

The tblIntake has the following indexes:

Field Name Primary Key Unique Ignore Nulls
BlockID No No No
GrowerID No No No
InTransFruitLog No No No
InFruitTypeIntakeID No No No
IntakeID Yes (auto number - increment) Yes No
GrowerID No No No
VarietyID No No No

In an effort to find which of the fields might be causing the key violation my next step was to run an append query with only one field at a time until I found the field causing the key violation. I have tried two fields SessionID and ChangeDate and both have thrown the key violation error. The SessionID is a unique identifier and now two records would have a duplicate value. The ChangeDate would be the date the record was changed. The query is reading the values from a form. If I change the query to a select query it will display a value for each field.

Can anyone please let me know what might be causing the problem and how I can determine which field is causing the problem?

All help is greatly appreciated.

Microsoft 365 and Office | Access | For business | Windows
0 comments No comments

2 answers

Sort by: Most helpful
  1. Kai-L 22,365 Reputation points Microsoft External Staff Moderator
    2026-10-02T19:16:04.29+00:00

    Dear Darren,

    You've already worked through this carefully, which helps narrow it down a lot. From my research, since appending only SessionID fails, and appending only ChangeDate fails too, the problem is probably not either of those fields. It's more likely related to the fields you aren't filling in, or to the table itself. The most likely causes are:

    1. Relationships in the back end database: If tblIntake is a linked table, the Relationships window in your front end won't show relationships defined in the back end. If a field such as GrowerID or BlockID is linked to a parent table with referential integrity enforced, any field you leave blank, or that defaults to 0, can trigger a key violation when no matching parent record exists. You can check this by opening the back end directly and going to Database Tools > Relationships > All Relationships.
    2. A combined unique index: Your index list shows GrowerID twice, which may mean some fields belong to a multi field index. If that index is set to unique, the combination of values can clash with an existing record even when each field looks fine on its own. You can check this in Design View > Indexes.
    3. The AutoNumber seed: Access can sometimes try to reuse an IntakeID that already exists, for example after an import. Back up the database first, then run Database Tools > Compact and Repair Database and try again.

    A quick way to tell these apart is to open tblIntake and add a record by hand without entering IntakeID. If that also fails, the cause is in the table. If it works, the cause is in what the append query sends.

    I hope this helps you track it down. Looking forward to your reply.


    If the answer is helpful, please click "Yes" and kindly upvote it. If you have extra questions about this answer, please click "Comment".  

    Note: Please follow the steps in the forum documentation to enable e-mail notifications if you want to receive the related email notification for this thread.  

    Was this answer helpful?

    1 person found this answer helpful.

  2. Nacif Boudlal 0 Reputation points
    2026-12-01T07:43:55.7966667+00:00

    Two things that should get you to the actual cause quickly.

    1. Your one-field-at-a-time test can't work on a SQL Server table. When you append only SessionID (or only ChangeDate), every other column is sent as NULL. If any column on the server is NOT NULL without a default, or is a foreign key, each of those test inserts fails, whichever field you pick. So that test doesn't point to a field; the summary dialog just counts all server-side rejections as "key violations".

    2. Let SQL Server tell you which constraint fails. Access keeps the server's own message in DBEngine.Errors; the append dialog doesn't show it. Run the query from VBA:

    
    Public Sub RunIntakeAppend()
    
        Dim db As DAO.Database, e As DAO.Error, msg As String
    
        Set db = CurrentDb
    
        On Error GoTo Failed
    
        db.Execute "qryAppendIntake", dbFailOnError + dbSeeChanges
    
        MsgBox db.RecordsAffected & " record(s) appended"
    
        Exit Sub
    
    Failed:
    
        For Each e In DBEngine.Errors
    
            msg = msg & e.Number & ": " & e.Description & vbCrLf
    
        Next
    
        MsgBox msg, vbExclamation
    
    End Sub
    
    

    (dbSeeChanges is needed because the table has an IDENTITY column; replace qryAppendIntake with your query name.) The first lines of the message usually name the object, for example The INSERT statement conflicted with the FOREIGN KEY constraint "FK_...", Cannot insert the value NULL into column '...', Violation of UNIQUE KEY constraint or String or binary data would be truncated.

    If you or your DBA can open SSMS, these show what the server enforces on that table today:

    
    EXEC sp_helpconstraint 'dbo.tblIntake';
    
    EXEC sp_helpindex 'dbo.tblIntake';
    
    SELECT name, is_disabled FROM sys.triggers WHERE parent_id = OBJECT_ID('dbo.tblIntake');
    
    

    Since it started on a given date with no code change, look for something new on the server (constraint, trigger, filtered unique index) or for a value that is new this season in the imported CSV (a new grower, block or variety code that doesn't exist yet in the parent table on SQL Server, as opposed to the old Access back end).

    I wrote up the other usual ODBC causes here: https://auscult.nbit-tech.fr/en/access-error-3146.html?utm_source=msqa&utm_medium=forum (disclosure: I make Auscult, the site linked).

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.