OpenQuery Method

Applies To

DoCmd Object.

Description

The OpenQuery method carries out the OpenQuery action in Visual Basic. For more information on how the action and its arguments work, see the action topic.

Syntax

DoCmd.OpenQuery queryname [, view] [, datamode]

The OpenQuery method uses the following arguments.

Argument

Description

queryname

A string expression that is 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, then in the current database.

view

One of the following intrinsic constants:

acNormal
acDesign
acPreview

If queryname is the name of a select, crosstab, union, or pass-through query whose ReturnsRecords property is set to -1, acNormal displays the query’s result set. If queryname refers to an action, data-definition, or pass-through query whose ReturnsRecords property is set to 0, acNormal runs the query.

If you leave this argument blank, the default (acNormal) is assumed.


Argument

Description

datamode

One of the following intrinsic constants:

acAdd

If you leave this argument blank, the default (acEdit) is assumed.


Remarks

If you specify the datamode argument and leave the view argument blank, you must include the view argument’s comma. If you leave a trailing argument blank, don’t use a comma following the last argument you specify.

See Also

DoCmd Object, OpenQuery Method, RunSQL Method.

Example

This example opens Sales Totals Query in Datasheet view and enables the user to view but not to edit or add records.


DoCmd.OpenQuery "Sales Totals Query", , acReadOnly