RunCode 宏操作

适用于:Access 2013、Office 2013

可以使用 RunCode 操作调用 Visual Basic for Applications (VBA) Function 过程。

Setting

RunCode 操作具有以下参数。

操作参数

说明

函数名称

要调用的 VBA Function 过程的名称。 请将所有函数参数放在括号中。 在“宏生成器”窗格“操作参数”部分的“函数名称”框中输入函数名称。 这是必需参数。

注意:在 Access 数据库 (.mdb 或 .accdb) 中,单击“ 生成 ”按钮以使用表达式生成器为此参数选择函数。 在表达式生成器中的列表中单击所需的函数。

备注

用户定义的 Function 过程都存储在 Microsoft Access 模块中。

即使 Function 过程不具有任何参数,括号也是必需的,如下面的示例所示:

TestFunction()

与用于事件属性设置的用户定义的函数名称不同的是,“函数名称”参数中的函数名称不以等号 (=) 开头。

Access 会忽略函数的返回值。

注意

如果函数名称与模块名称相同,则不能通过宏调用 Function 过程。

提示

要运行用 Visual Basic 编写的 Sub 过程或事件过程,请创建一个调用 Sub 过程或事件过程的 Function 过程。 然后使用 RunCode 操作运行该 Function 过程。

If you use the RunCode action to call a function, Access looks for the function with the name specified by the Function Name argument in the standard modules for the database. However, when this action runs in response to clicking a menu command on a form or report or in response to an event on a form or report, Access first looks for the function in the form's or report's class module and then in the standard modules. Access doesn't search the class modules that appear in the Modules area of the Navigation Pane for the function specified by the Function Name argument.

此操作不能在 VBA 模块中使用。 然而,可以直接在 VBA 中运行所需的 Function 过程。