VBA & Macro Problems

Fix Excel VBA SQL Reserved Words Error When Querying Access Data

John WilsonJohn Wilson Nov 2, 2026 869 views

Question details

The user encounters a reserved-words error in Excel VBA when executing an Access SQL query via ADODB, despite the same query executing successfully within Microsoft Access.

Fix Excel VBA SQL Reserved Words Error When Querying Access Data
Product
Microsoft Excel, Microsoft Access
Device & OS
not provided
Scenario
Running a SELECT query on an Access database using the ADODB provider in Excel VBA.
Observed behavior
Excel VBA throws a reserved-words error and fails to execute the query, even though Microsoft Access processes the exact same SQL string without errors.
Before you start

Ensure you have permission to modify the underlying Microsoft Access database structure or the exact SQL query string being executed in your VBA code.

Solution 1Recommended

Rename Reserved Fields or Escape Them in Your SQL Query

Identify and resolve reserved word conflicts by renaming fields in your Access database or wrapping them in square brackets within your VBA SQL string.

Microsoft Access and the ADODB provider interpret SQL differently. Access natively forgives the use of certain reserved words (like 'Year', 'Month', or 'Day'). However, ADODB strictly enforces SQL syntax rules, which causes queries called from Excel VBA to fail if reserved words are left unprotected.

1
Open Access Database

Launch Microsoft Access and open the database table you are querying in Design View.

2
Identify Reserved Words

Review your field names for common SQL reserved words such as 'Date', 'Year', 'Month', 'Day', 'Time', or 'Name'.

3
Rename Fields

Rename the conflicting fields to non-reserved alternatives (e.g., change 'Year' to 'OrderYear') and save the table.

4
Modify the VBA SQL String

If renaming fields is not an option, update your Excel VBA code to enclose the reserved words in square brackets. For example, change 'SELECT Year, Month FROM TableName' to 'SELECT [Year], [Month] FROM TableName'.

Avoid SELECT *: Instead of using 'SELECT *', explicitly list the required columns in your query. This prevents sudden ADODB errors if someone later adds a new column with a reserved name to the database.
Free Microsoft Office alternative

Use WPS Office for a Seamless Spreadsheet Experience

While complex ADODB Access queries are specific to Microsoft environments, WPS Office provides a lightweight, highly compatible, and free alternative for your daily spreadsheet and data analysis needs. Enjoy advanced data processing without the heavy system overhead.

  1. 1. Download and Install: Visit the official WPS website to download and install WPS Office for free.
  2. 2. Open Your Spreadsheets: Launch WPS Spreadsheets and seamlessly open your existing .xlsx or .xls files without losing formatting.
  3. 3. Analyze Data: Use built-in advanced formulas and pivot tables to process your data efficiently.
Fully compatible with Microsoft Excel formats (.xlsx, .xls, .csv).Free, lightweight, and fast-loading office suite.Familiar user interface requires no learning curve.Advanced data analysis and pivot table capabilities.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my query work in Microsoft Access but fail in Excel VBA?

Microsoft Access uses its native database engine, which is more forgiving of reserved words in field names. Excel VBA uses the ADODB provider to connect to the database, which strictly adheres to standard SQL syntax rules and flags unprotected reserved words as errors.

What are the most common SQL reserved words that cause ADODB errors?

Common SQL reserved words that frequently cause syntax errors include Date, Time, Year, Month, Day, Name, Select, Table, Value, and Index. Using these as column names without brackets triggers errors in ADODB.

How do I escape reserved words in an ADODB SQL string?

You can escape reserved words by wrapping the specific column names in square brackets within your SQL query string. For example, write `SELECT [Date], [Name] FROM Users` instead of `SELECT Date, Name FROM Users`.

Is it bad practice to use `SELECT *` in Excel VBA ADODB queries?

Yes, it is generally discouraged. Using `SELECT *` retrieves all columns, meaning if a database administrator later adds a column with a reserved name, your VBA query will suddenly break. Explicitly defining only the columns you need is safer and improves query performance.