Run Microsoft Access Action Queries Without Opening Datasheets
Question details
Run append and delete queries without displaying datasheets, then update the relevant subforms.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A Search button runs several action queries, including an append query that uses a crosstab as its source.
- Observed behavior
- A query datasheet can appear before the main form instead of showing only the refreshed subforms.
Identify the saved append and delete query names in the Navigation Pane and find the Search button's Click event in the VBA editor. Confirm the names of the subform controls you want to update.
Use CurrentDb.Execute for action queries and requery subforms
Replace DoCmd.OpenQuery calls for append and delete queries to run them without opening datasheets.
Execute is appropriate for action queries, not for opening a crosstab or other SELECT query as a datasheet. An append query can still use a crosstab query as its source.
Open the form in Design View, select the Search button, and use Property Sheet > Event > On Click to open its event procedure.
Replace each DoCmd.OpenQuery call for an append or delete query with CurrentDb.Execute "QueryNameGoesHere", dbFailOnError. For example, use CurrentDb.Execute "Output_Total_App", dbFailOnError for the saved append query.
After all action queries finish, add Me!SubformControlName.Form.Requery for each subform, replacing SubformControlName with the control name on the main form. This example assumes the code runs in the main form's module.
Save the VBA changes, return to Form View, and click Search. Verify that the action queries complete without opening datasheets and that the subforms show the updated records.

Work with Office files in WPS Office
WPS Office is a free, lightweight alternative for everyday document and spreadsheet work, with a familiar interface and Office format compatibility for easier migration. It does not run Microsoft Access action queries or replace Access databases.

Frequently Asked Questions
Why does DoCmd.OpenQuery show a datasheet?
DoCmd.OpenQuery can open a query in Datasheet view. For saved append and delete queries, use CurrentDb.Execute with the query name instead to run the action without opening that view.
Can I use Execute on a crosstab query?
Execute is for action queries, not a crosstab SELECT query. If a saved append query uses the crosstab as its source, execute the append query by name.
How do I show the new records in a subform?
After the action queries finish, call Me!SubformControlName.Form.Requery from the main form's module. Use the subform control name, which may differ from the form object's name.
What does dbFailOnError do?
It tells Access to raise an error if the action query fails. Include VBA error handling in the button's Click event to report the failure.




