You can use the OpenQuery macro action in Access databases to open a select or crosstab query in Datasheet view, Design view, or Print Preview. This action runs an action query. You can also select a data entry mode for the query.
Note: This action is only available in the Access database environment (.mdb or .accdb). See the OpenView, OpenStoredProcedure, or OpenFunction actions if you are using the Access project environment (.adp). The OpenQuery macro action isn't available in Access web apps.
The OpenQuery macro action has the following arguments.
The name of the query to open. Select the name of the query to open using the drop-down list of query names. This is a required argument.
If you run a macro containing the OpenQuery action in a library database, Access first looks for the query with this name in the library database, and then in the current database.
The view in which the query will open. Select Datasheet, Design, Print Preview, PivotTable, or PivotChart in the View box. The default is Datasheet.
Note: PivotTable and PivotChart views aren't available in versions of Access beginning with Access 2013.
The data entry mode for the query. This applies only to queries opened in Datasheet view. Select Add (the user can add new records but can't edit existing records), Edit (the user can edit existing records and add new records), or Read Only (the user can only view records). The default is Edit.
If you use Datasheet for the View argument, Access displays the result set if the query is a select, crosstab, union, or pass-through query whose ReturnsRecords property is set to Yes; and it runs the query if it is an action, data-definition, or pass-through query whose ReturnsRecords property is set to No.
The OpenQuery action is similar to double-clicking the query in the Navigation Pane, or right-clicking the query in the Navigation Pane and selecting a view. With this action you can select additional options.
You can drag a query from the Navigation Pane to the macro design window. This automatically creates an OpenQuery action that opens the query in Datasheet view.
Switching to Design view while the query is open removes the Data Mode argument setting for the query. This setting isn't in effect even if the user returns to Datasheet view.
If you don't want to display the system messages that normally appear when an action query is run (indicating it is an action query and showing how many records will be affected), you can use the SetWarnings action to suppress the display of these messages.
To run the OpenQuery macro action in a Visual Basic for Applications (VBA) module, use the OpenQuery method of the DoCmd object.