Others

Run Microsoft Access Queries in VBA Without Datasheet View

Huda QurayshiHuda Qurayshi Nov 22, 2026 869 views

Question details

Run a Microsoft Access query from VBA without displaying its results in Datasheet view.

Run Microsoft Access Queries in VBA Without Opening Datasheet View
Product
Microsoft Access
Device & OS
not provided
Scenario
A VBA procedure needs to process a saved query in the background.
Observed behavior
DoCmd.OpenQuery opens a SELECT query in Datasheet view, while action queries can be executed directly.
Before you start

Identify whether the saved query is an action query, such as UPDATE or DELETE, or a SELECT query. Confirm its name in the Navigation Pane and check whether it requires parameters.

Solution 1Recommended

Execute an action query without opening Datasheet view

Use CurrentDb.Execute for saved queries that add, update, delete, or make tables.

1
Open the VBA editor

In Access, open the database and choose Database Tools > Visual Basic. Open the module containing your procedure.

2
Execute the saved query

Add `CurrentDb.Execute "queryname", dbFailOnError` to the procedure, replacing `queryname` with the saved action query's name.

3
Run the procedure

Run the procedure from the VBA editor or its assigned button. Handle any error raised by the Execute statement in your VBA code.

Execute an action query without opening Datasheet view
Action queries only: CurrentDb.Execute does not return SELECT query results. The dbFailOnError option raises an error if affected records cannot be updated.
Free Microsoft Office alternative

Work with Office documents in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with documents, spreadsheets, and presentations. Its Microsoft Office format support helps you move existing files into your workflow. It does not run Microsoft Access queries or replace Access VBA.

Open and edit Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXUse a familiar interface to make the transition from Microsoft Office easierWork with spreadsheet data in WPS Spreadsheets alongside your Access workflowUse a free, lightweight suite for everyday office tasks
microsoft office alternative - wps office

Frequently Asked Questions

Why can't CurrentDb.Execute run my SELECT query?

CurrentDb.Execute is intended for action queries, not queries that return a result set. Use CurrentDb.OpenRecordset to read a SELECT query's results in VBA.

How can I view a SELECT query's results instead?

Use `DoCmd.OpenQuery "queryname"` in VBA, replacing the name with your saved query. This opens the query for viewing in Datasheet view.

What does dbFailOnError do for an action query?

When supplied to CurrentDb.Execute, dbFailOnError raises an error if affected records cannot be updated. Add VBA error handling to respond to that error.

How do I run a SELECT query that requires parameters?

Create or reference a DAO QueryDef for the saved query, assign values to its Parameters collection, and then call its OpenRecordset method.