来自 'hybrid' 访问 Web 数据库错误的 RunCode 宏操作

RunCode macro action from 'hybrid' Access web database error

我有一个 Access 网络数据库

通过执行以下步骤可以轻松重现此问题:

  1. 在 MS Access
  2. 中创建一个空白 web 数据库
  3. 添加并保存 table
  4. 从那个 table 创建一个默认表单并在上面放一个按钮
  5. 创建一个新的 VBA 模块 "Module1" 并将以下函数放入其中:

    Public Function DoTest()
        MsgBox "Test function runs smoothly"
    End Function
    
  6. 使用 RunCode: Function Name: DoTest() 创建一个客户端宏 "Macro1"(请注意,IntelliSense 可以识别该宏,并且从这里运行良好)
  7. 创建表单按钮的单击宏事件RunMacro: Macro Name: Macro1
  8. 在表单视图中单击表单按钮收到错误:

The function you entered can't be used in this expression.

  • You may have used a DoEvents, LBound, UBound, Spc, or Tab function in an expression.
  • You may have used an aggregate function, such as Count, in a design grid or in a calculated control or field.

单击 "Ok" 会显示错误编号 2426 或 2950,具体取决于您在客户端宏的 RunCode 命令中是否在函数名称前有等号。

我已经尝试了这个 very similar question 中的所有提示,但没有任何运气。 Access 似乎发现函数很好,因为用乱码替换函数名称会产生非常不同的错误。

我到底做错了什么?

在我使用发布到 SharePoint 2010 的 Access Services 的实际 Web 数据库中,我在表单按钮的单击事件上使用 If IsClient() Then 宏语句以确保 VBA 只是 运行 在客户端模式下,但这与我收到的错误无关。

经过一些额外的挖掘,我发现了 this post in another forum。 在这里,作者简单地解释说我正在尝试做的事情不起作用(当你认为它应该起作用时)。

因为它在另一个论坛上,所以我将详细说明对我也有效的解决方法(来源:jakedrew,UtterAccess post,2011 年 6 月 9 日)。基本上,除了客户端宏之外,您还需要使用客户端表单作为从 Web 表单到 VBA 的中间步骤。我通过执行以下操作使它对我当前的应用程序有效:

  1. 我将函数重新保存为子函数:

    Public Sub DoTest(ByVal intArg As Integer)
        MsgBox "Test sub runs smoothly with argument = " & intArg
    End Sub
    
  2. 创建一个客户端表单(我的名为 "frmVBA_Bridge")并创建以下 OnOpen 事件:

    Private Sub Form_Open(Cancel As Integer)
        ' run your code using this command.  Note that if you don't have an argument, you won't include the part of this line following the comma
        Application.Run TempVars("SubName").Value, TempVars("Arg1").Value
        ' reset the "parameters"
        TempVars("SubName").Value = ""
        TempVars("Arg1").Value = 0
        DoCmd.Close acForm, Me.Name, acSaveYes
    End Sub
    
  3. 客户端宏 "Macro1" 现在改为:

    OpenForm
      Form Name  frmVBA_Bridge
      View Form
      Where Condition
      Data Mode
      Window Mode  Hidden
    
  4. Web 表单按钮的点击嵌入宏更改为:

    If  IsClient() = True Then
      SetTempVar
        Name SubName
        Expression ="DoTest"
      SetTempVar
        Name Arg1
        Expression = 100
      RunMacro
        Macro Name Macro1
    End If
    

对于这样一个简单的事情有相当多的解决方法,但它似乎可以完成工作!