Description
You can use the OpenQuery action 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.
Setting
The OpenQuery action has the following arguments.
Action argument | Description |
Query Name | The name of the query to open. The Query Name box in the Action Arguments section of the Macro window shows all queries in the current database. This is a required argument. If you run a macro containing the OpenQuery action in a library database, Microsoft Access looks for the query with this name first in the library database, then in the current database. |
View | The view in which the query will open. Click Datasheet, Design, or Print Preview in the View box. The default is Datasheet. |
Data Mode | The data entry mode for the query. This applies only to queries opened in Datasheet view. Click 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. |
Remarks If you use Datasheet for the View argument, Microsoft 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 were an action, data-definition, or pass-through query whose ReturnsRecords property is set to No.
The OpenQuery action is similar to clicking the Open button or Design button in the Database window after selecting a query in the Queries tab. With this action you can select additional options. Tip You can select a query in the Database window and drag it to a macro action row. 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. Tip If you don't want to display the system messages that normally appear when an action query is run (indicating it's 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 action in Visual Basic, use the OpenQuery method of the DoCmd object.See Also OpenQuery method, RunSQL action, SetWarnings action.