Fix Duplicate Values Error When Creating an Access Composite Key
Question details
The user needs to resolve the Microsoft Access error that appears when adding a composite primary key or unique index and reports that changes would create duplicate values.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- The user is maintaining a BookTOC linking table with BookID and PageNumber and wants to add a composite primary key or unique index to prevent duplicate combinations.
- Observed behavior
- Access reports that the changes would create duplicate values even though visible values appear unique, caused by duplicate pairs, hidden Nulls, blank records, or existing index data.
Open the Access table in Datasheet View and inspect the BookID and PageNumber fields for empty cells. If the table contains blank placeholder rows that are not real records, plan to remove them before changing the index.
Remove duplicate combinations, Nulls, and blank records before adding the composite key
Use this when you want to keep the composite primary key on BookID and PageNumber and need to clean the existing data first.
A composite key treats the combination of BookID and PageNumber as unique. Access blocks the key when any pair is repeated or when hidden blanks and Nulls are present, so cleaning the table is required even if individual columns look unique.
In Microsoft Access, open the target table and switch to Datasheet View so you can see all rows.
Click Create > Query Wizard > Find Duplicates Query Wizard, select the table, then select BookID and PageNumber as the duplicate fields to locate repeated combinations.
Review the query results and delete or merge the duplicate BookID/PageNumber records so each combination appears only once.
Use the column filter arrows in Datasheet View to show only blanks for BookID and PageNumber, then delete unused blank rows or fill in the required values.
Click Database Tools > Compact and Repair Database, save the table, then recreate the composite primary key.

Use an AutoNumber primary key and a multi-field unique index on BookID and PageNumber
Choose this when you prefer a simple surrogate primary key and still need to prevent duplicate BookID and PageNumber combinations.
Manage Excel, Word, and PowerPoint files free with WPS Office
WPS Office does not include an Access database repair tool, but it is a free, lightweight Microsoft Office alternative for everyday Word, Excel, and PowerPoint work, with familiar layouts and strong DOCX, XLSX, and PPTX compatibility.
- 1. Download WPS Office: Visit the official WPS Office download page and download the free installer for your device.
- 2. Install and launch: Run the installer and open WPS Office, then choose Writer, Spreadsheets, or Presentation.
- 3. Open Microsoft-compatible files: Open your existing DOCX, XLSX, or PPTX files to view, edit, and save them in the familiar office interface.

Frequently Asked Questions
Why does Access report duplicate values when adding a composite key?
Access checks the combined values of the key fields. Repeated BookID and PageNumber pairs, hidden blanks, Null values, or leftover index data can trigger the message even when individual columns look unique. Run a Find Duplicates query and filter each field for blanks before applying the key.
Can I use BookID and PageNumber as a composite primary key in an Access linking table?
Yes. Open the table in Design View, remove blank placeholder rows and duplicate combinations, select both BookID and PageNumber rows, and click Primary Key. Alternatively, create a separate multi-field unique index on those fields.
What should I do if my Access composite key still fails after removing visible duplicates?
Filter both fields for blanks and Nulls, remove unnecessary empty records, and click Database Tools > Compact and Repair Database. Then close and reopen the table before re-creating the index.
Is an AutoNumber primary key better than a composite key in Access?
It can be simpler. Add an AutoNumber field as the primary key and create a unique multi-field index on BookID and PageNumber to enforce the uniqueness rule without making business fields the primary key.
Does WPS Office repair Microsoft Access database errors?
WPS Office does not have a Microsoft Access database engine or repair tool for ACCDB files. It is a free alternative for Word, Excel, and PowerPoint documents and spreadsheets with DOCX, XLSX, and PPTX compatibility.




