Access error reference
Access error 3022: duplicate values in index or key
A user creates a record, or a button adds rows, and Access refuses: the changes “would create duplicate values”. The value typed or computed already exists in a field that does not accept duplicates — often the primary key.
The message

The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
On a French Access (Microsoft 365): « Modifications non effectuées : risque de doublons dans champs index, clé principale ou relation interdisant les doublons. Modifiez les données des champs contenant les doublons, enlevez ou redéfinissez l'index pour permettre les doublons et recommencez. »
Where it shows up
When a record is saved in a data-entry form, in code that adds or edits rows (rs.AddNew then rs.Update, CurrentDb.Execute … , dbFailOnError), and in an append or update query run from code. Run by hand or through DoCmd.RunSQL, the same query shows a warning instead — “key violations” — and the duplicate rows are not added.
Common causes
- an AutoNumber out of step: after an append query that copied the numbers, or a repaired database, the next number handed out already exists;
- a no-duplicates index on a field that receives one: a name, an order number, a reference entered twice;
- a primary key computed in code (
DMax("ID", "T") + 1) that two PCs compute at the same moment; - an append query copying rows already there, for instance an import run twice;
- a composite key (two fields) whose combination already exists, or a one-to-one relationship.
How to reproduce and check it
- Open the table in Design view, then Indexes (Table Design tab): note the indexes whose Unique property is Yes, and the primary key.
- Look for the duplicate value with a query:
SELECT Ref, Count(*) FROM T GROUP BY Ref HAVING Count(*) > 1, or check whether the value being added already exists. - For an AutoNumber, compare
DMax("ID", "T")with the number Access tries to give a new record.
How to fix it
If the value must be unique, the data is what needs fixing: warn the user before saving. If the index has no reason to be unique, set it to “Yes (Duplicates OK)”. An AutoNumber out of step is sometimes reset by Compact and Repair; otherwise, by a statement that sets the next number.
Back up the database before running the ALTER TABLE statement, and run it when nobody is using the table. If the primary key is an AutoNumber linked to other tables by relationships, do not change its values: only reset the counter.
What Auscult reports
The diagnostic records 3022 wherever Access returns it during the run, and files it among the faults to fix, with the object that produces it. It does not run queries that would change data: a duplicate that only real data entry would trigger may not appear during the run. The report does flag, among the data risks, tables without a primary key, where duplicates get in without any message.
Related errors
- 3021 — no current record, the other error of code that writes to tables
- 2501 — action canceled, when a form refuses to save and the code carries on
- The Access error reference, code by code