Prevent Duplicate Field Pairs in a Microsoft Access Append Query
Question details
Add purchase-order records only when their Sales Document and Item combination is not already in the destination table.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- An append query maps Sales Document and Item from purchase-order records to SalesNumber and LineNo in a destination table.
- Observed behavior
- Each SalesNumber and LineNo pair should occur only once in the destination table.
Confirm that the append query maps Sales Document to SalesNumber and Item to LineNo. Check the destination table for existing duplicate SalesNumber and LineNo pairs, because Access cannot create a unique index until those duplicates are resolved.
Create a composite unique index on the destination fields
Use a two-field unique index to prevent duplicate SalesNumber and LineNo combinations from being added to the destination table.
The index enforces uniqueness for the combination of both fields, rather than requiring each field to be unique on its own.
In the Access Navigation Pane, right-click the destination table and select Design View.
On the Table Design tab, select Indexes to open the index list.
In a blank row, enter an index name and select SalesNumber in the Field Name column. On the next row, leave Index Name blank and select LineNo as the Field Name.
Select the named index row and set Unique to Yes in Index Properties. Close the Indexes window and save the table.
Open the append query, confirm its field mappings, and select Run. Access reports key violations for records whose field pairs conflict with the unique index.

Review Purchase-Order Data in WPS Spreadsheets
WPS Office is a free, lightweight Office alternative with a familiar interface and Microsoft Office format compatibility for an easy transition. Use WPS Spreadsheets to review purchase-order data exported to a spreadsheet; the Access unique index must still be created in Microsoft Access.

Frequently Asked Questions
Can the same SalesNumber appear on more than one record?
Yes. A composite unique index permits the same SalesNumber on multiple records as long as each SalesNumber and LineNo combination is unique.
Why can't Access create my unique index?
The destination table may already contain duplicate SalesNumber and LineNo pairs. Find and resolve those duplicates, then return to Design View, open Indexes, and set the index's Unique property to Yes.
What happens when the append query encounters a duplicate pair?
The unique index prevents that record from being added, and Access reports a key violation. Other valid records may still be appended.
Does WPS Office enforce the unique index in my Access database?
No. Create and manage the composite unique index in Microsoft Access. WPS Spreadsheets can help you review exported purchase-order data in an XLSX file.




