适用于:Access 2013、Office 2013
可以使用 OpenQuery 操作在数据表视图、设计视图或打印预览中打开选择查询或交叉表查询。 此操作运行动作查询。 您还可以为查询选择数据输入模式。
注意
[!注释] 此操作仅适用于 Microsoft Access 数据库环境(.mdb 或 .accdb)。 如果使用的是 Microsoft Access 项目环境 (.adp),请参阅 OpenView、 OpenStoredProcedure 或 OpenFunction 操作。
Setting
OpenQuery 操作具有下列参数。
操作参数 |
说明 |
|---|---|
查询名称 |
要打开的查询的名称。 “宏生成器”窗格“操作参数”部分中的“查询名称”框显示当前数据库中的所有查询。 这是必需的参数。如果在库数据库中运行包含 OpenQuery 操作的宏,Microsoft Access 首先在库数据库中查找具有此名称的查询,然后在当前数据库中查找。 |
View |
将在其中打开查询的视图。 请在“视图”框中单击“数据表”、“设计”、“打印预览”、“数据透视表”或“数据透视图”。 默认值为“数据表”。 |
数据模式 |
查询的数据输入模式。 这仅适用于在数据表视图中打开的查询。 请单击“添加”(用户可添加新记录,但不能编辑现有记录)、“编辑”(用户可编辑现有记录和添加新记录)或“只读”(用户只能查看记录)。 默认值为“编辑”。 |
备注
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.
OpenQuery 操作类似于在导航窗格中双击查询,或在导航窗格中右键单击查询并选择视图。 通过此操作可以选择其他选项。
提示
- You can drag a query from the Navigation Pane 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.
- 如果不想显示通常在运行动作查询时出现的系统消息(指示查询为动作查询并显示将受到影响的记录数),则可以使用 SetWarnings 操作禁止显示这些消息。
要在 Visual Basic for Applications (VBA) 模块中运行 OpenQuery 操作,请使用 DoCmd 对象的 OpenQuery 方法。