DoCmd.OpenQuery (Access)
The OpenQuery method carries out the OpenQuery action in Visual Basic.
You can use the OpenQuery method 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.
OpenQuery (QueryName, View, DataMode)
DoCmd.OpenQuery "Sales Totals Query", , acReadOnly
Arguments
The following argument is required
QueryName (String) - A string expression that's the valid name of a query in the current database. If you execute Visual Basic code containing the OpenQuery method in a library database, Microsoft Access looks for the query with this name first in the library database, and then in the current database.
Optional arguments
The following arguments are optional
View (AcView) - An AcView constant that specifies the view in which the query will open. The default value is acViewNormal.
Possible values are
acViewDesign | Design view |
acViewLayout | Layout view |
acViewNormal | Normal view |
acViewPivotChart | PivotChart view |
acViewPivotTable | PivotTable view |
acViewPreview | Print Preview |
acViewReport | Report view |
DataMode (AcOpenDataMode) - An AcOpenDataMode constant that specifies the data entry mode for the query. The default value is acEdit.
Possible return values are acAdd - The user can add new records but can't view or edit existing records, acEdit - The user can view or edit existing records and add new records, acReadOnly - The user can only view records.