【问题标题】:MS Access VBA Me.Recordset.Findfirst Runtime ErrorMS Access VBA Me.Recordset.Findfirst 运行时错误
【发布时间】:2018-10-24 07:51:03
【问题描述】:

我的一个 vba 事件有问题。

首先,在字段发生更改后触发事件,该字段属于显示来自一个表的多个数据条目的表单,该表单位于 NavigationPane 内。

我的数据库是在 access 2016 32bit 中编程的,主要由我们的工作人员在带有 Access Runtime 2013 的服务器上使用

现在,当我在我的电脑上触发事件时,一切都按预期工作,但在服务器运行时版本上它显示一个错误,我将尝试将其翻译成英文,因为我在德国:“这个程序的执行无法继续,由于运行时错误” - “此程序无法继续运行并将被关闭”。

我已经尝试过翻阅鸭子,但找不到我需要的东西,主要是因为关键字“运行时”在这种情况下有两种不同的含义。

这是代码:

Private Sub isEnd_AfterUpdate()
Dim isEnd As Date
Dim rs As Recordset
Dim strFind As String
Dim test As Variant

'On Error Resume Next

Set rs = Recordset

With rs
If Not .EOF Then
        isEnd = Me!isEnd
    If Me!isStart > 0 Then
        Me!isDur = (Me!isEnd - Me!isStart) * 24
    End If

    strFind = "IdMa = '" & Me!IdMa & "' and OrderRow = " & Me!OrderRow + 1
    'test = MsgBox(strFind & " - " & rs.Name & " - '" & isEnd & "'", vbOKOnly, "test")
    Me.Recordset.FindFirst (strFind)
    Me!isStart = isEnd
    Me.isEnd.SetFocus
End If
End With
End Sub

您可以忽略我尝试用于调试的错误处理和 MsgBox。

Database 是用于规划我们的流程,该字段保存已完成流程的结束时间,并应将其输入到下一个流程的开始时间,以节省一点时间。

编辑1: 我应该提一下,我将错误精确到了这一行:

Me.Recordset.Findfirst (strFind)

但不知道为什么这是个问题,完全相同的行在同一个表单上的某些按钮中使用得很好。

【问题讨论】:

  • 你想用'Set rs = Recordset'行做什么
  • 它应该引用我表单中的记录集,这确实有效。

标签: ms-access vba ms-access-2013 ms-access-2016


【解决方案1】:

尝试使用 RecordsetClone 并且不要重复控件名称:

Private Sub isEnd_AfterUpdate()

    Dim isEndDate As Date
    Dim rs As DAO.Recordset
    Dim strFind As String
    Dim test As Variant

    'On Error Resume Next

    Set rs = Me.RecordsetClone

    With rs
        If Not .EOF Then
            isEndDate = Me!isEnd
            If Me!isStart > 0 Then
                Me!isDur = (Me!isEnd - Me!isStart) * 24
            End If

            strFind = "IdMa = '" & Me!IdMa & "' and OrderRow = " & Me!OrderRow + 1
           'test = MsgBox(strFind & " - " & .Name & " - '" & isEnd & "'", vbOKOnly, "test")
            .FindFirst strFind
            ' and use the found record for something ..?

            Me!isStart.Value = isEndDate
            Me!isEnd.SetFocus
        End If
        .Close
    End With

End Sub

【讨论】:

  • 我确实将它用于以后注入我的 isEndDate 值并聚焦下一个字段。我现在没有时间测试这个,但下周会回来,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多