How to Run an Access Append Query in VBA Using Form Controls
Question details
The user needs to execute an append query in MS Access using VBA and values from form controls, but encounters errors because the database engine does not automatically recognize form references.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Attempting to insert new records into a target table via VBA by referencing the current values of text boxes and combo boxes on an active Access form.
- Observed behavior
- The append query fails to execute because DAO operates at the database engine level and cannot directly interpret UI form control variables inside a raw SQL query string.
Ensure your Access database is stored in a Trusted Location so VBA code can run, and double-check the exact names of your target table and form controls before building the SQL statement.
Construct the SQL Statement by Concatenating Form Controls
Directly build the SQL string in VBA by appending the current values of the form controls into the query text before executing it.
DAO executes at the database engine level, meaning it cannot resolve expressions like 'Forms!FormName!ControlName' directly within an SQL string literal. To fix this, you must construct the string dynamically by concatenating the form values into the VBA string variable before passing it to the Execute method.
Open your VBA editor and declare a String variable for your SQL statement and a DAO.Database variable (e.g., Dim sql As String, dbs As DAO.Database).
Build your INSERT INTO statement by stepping outside the string literal to append form references. Use single quotes for text values. For example: sql = "INSERT INTO [TargetTable] (CompanyName) VALUES ('" & Forms!Form1!Text1 & "')"
Assign the current database to your DAO variable by typing: Set dbs = CurrentDb
Run the SQL command using the dbFailOnError option to ensure execution errors are caught: dbs.Execute sql, dbFailOnError

Looking for a Reliable and Free Office Suite? Try WPS Office
While Microsoft Access handles complex relational databases, most everyday data management, tracking, and reporting tasks can be completed much faster using powerful spreadsheet software. WPS Office provides a lightweight, completely free, and highly compatible alternative to Microsoft Office.
- 1. Download and Install: Get WPS Office for free from the official website and install it on your device in minutes.
- 2. Open Existing Files: Easily open your exported database tables (.csv or .xlsx) directly in WPS Spreadsheet without format loss.
- 3. Manage Data Quickly: Use built-in data forms, pivot tables, and advanced formulas to manipulate and analyze your data seamlessly.

Frequently Asked Questions
Why do I get a "Too few parameters" error when running an Access query via VBA?
This error happens because the DAO database engine does not recognize Access form controls embedded directly inside the SQL text. You must extract the control values and concatenate them into the SQL string or use a QueryDef object to evaluate them properly.
What is the purpose of dbFailOnError in the DAO Execute method?
Adding dbFailOnError ensures that if the action query fails (due to key violations, locked records, or type mismatches), VBA generates a run-time error that you can trap, and automatically rolls back any partial changes.
Do I need to format dates when concatenating them into an Access SQL string?
Yes. When concatenating dates into an Access SQL string in VBA, you must enclose the date values in hash symbols (#) and ideally format them in the US date format (mm/dd/yyyy) to prevent the database engine from misinterpreting the days and months.
Can I use parameterized queries instead of string concatenation in Access VBA?
Yes. Using a saved QueryDef and passing parameters dynamically is the recommended approach for production databases. It automatically resolves issues with apostrophes in text fields and secures your database against SQL injection attacks.




