VBA & Macro Problems

Fix Microsoft Access Append Query Parameters and Duplicate Keys

Khadija KhanKhadija Khan Nov 27, 2026 869 views

Question details

The user needs to run an Access append query that uses a form control and display a custom message for duplicate keys.

Fix Access Append Query Parameters and Duplicate Key Handling
Product
Microsoft Access
Device & OS
not provided
Scenario
A VBA procedure runs an append query using an ID from an open form.
Observed behavior
The query reports a too-few-parameters error, described as run-time error 3601, and the user wants to handle duplicate IDs.
Before you start

Open the form that contains the ID control and confirm the form, control, table, and key-field names. In the VBA editor, check Err.Number and Err.Description; too-few-parameters errors are commonly reported as error 3061.

Solution 1Recommended

Read the form value and handle duplicate keys in VBA

Use this approach when the ID is numeric and you want to check for an existing record before running the append query.

The example uses a numeric CustomerID from frmEntry and appends it to the Customers table. Replace these names with your own and add any other fields required by the destination table.

A pre-check improves the message, but another user could insert the same key before the query runs. Keep a unique index on the key and handle error 3022 as well.

1
Open the VBA editor

In Access, press Alt+F11 and open the module or form procedure that runs the append query.

2
Add the append procedure

Adapt and run this example from your button's Click event or another procedure: Public Sub AppendCustomer() On Error GoTo ErrorHandler Dim customerId As Long Dim sql As String If (SysCmd(acSysCmdGetObjectState, acForm, "frmEntry") And acObjStateOpen) = 0 Then MsgBox "Open the entry form first." Exit Sub End If If IsNull(Forms!frmEntry!CustomerID) Then MsgBox "Enter a customer ID." Exit Sub End If customerId = CLng(Forms!frmEntry!CustomerID) If Not IsNull(DLookup("CustomerID", "Customers", "CustomerID=" & customerId)) Then MsgBox "This customer ID already exists." Exit Sub End If sql = "INSERT INTO Customers (CustomerID) VALUES (" & customerId & ")" CurrentDb.Execute sql, dbFailOnError Exit Sub ErrorHandler: If Err.Number = 3022 Then MsgBox "This customer ID already exists." Else MsgBox "Error " & Err.Number & ": " & Err.Description End If End Sub

3
Test both outcomes

Open frmEntry, enter a new ID in CustomerID, and run the procedure. Then enter an existing ID and confirm that the custom duplicate message appears.

Read the form value and handle duplicate keys in VBA
Match the field type: This example is for numeric IDs. Text IDs require different handling; a typed DAO parameter is preferable to concatenating text into SQL.
Free Microsoft Office alternative

Work with exported Access data in WPS Spreadsheets

WPS Office is a free, lightweight alternative for working with Office documents in a familiar interface. Export Access data to an Excel workbook to review it in WPS Spreadsheets; WPS does not fix Access append queries or run Access VBA.

Review and organize exported Access records in a spreadsheetOpen and edit Microsoft Excel XLSX filesUse a familiar spreadsheet interface for an easier move from OfficeWork with a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Access append query ask for a parameter?

Access may not be able to resolve a form control, field name, or other expression. Open the referenced form, check the names in SQL View, and explicitly assign parameters when executing a DAO QueryDef.

How can I see the parameters Access expects?

Press Ctrl+G in the VBA editor to open the Immediate window. Loop through the saved QueryDef's Parameters collection and print each parameter's Name with Debug.Print.

How do I show a custom message for a duplicate key?

Execute the append query with dbFailOnError and use a VBA error handler to check for Err.Number 3022. Display your message with MsgBox, and retain a unique index on the key field.

Can WPS Office run my Access append query?

No. Run Access append queries and Access VBA in Microsoft Access. You can export records to an Excel workbook and review them in WPS Spreadsheets.