1

我不断收到“文件共享锁定计数已超过”的错误消息。有一些变通方法可以增加每个会话的注册表或更改注册表文件,但我不希望用户必须经历这些。有谁知道为什么我可能会收到这样的错误?

这是我的代码:

Dim rst As DAO.Recordset
Dim rstCopy As DAO.Recordset
Dim Counter As Long

Set rst = dbs.openrecordset("SELECT * FROM [Qry_Calculate_Picking_Times]", dbopendynaset)
Set rstCopy = dbs.openrecordset("SELECT * FROM [Qry_Calculate_Picking_Times]", dbopendynaset)

rst.MoveLast
Counter = rst.RecordCount
rst.MoveFirst

rst.MoveNext
Counter = Counter - 1

While Counter > 0

With rst

If ![OWPPCK] <> rstCopy![OWPPCK] Or ![JustDate] <> rstCopy![JustDate] Or DateDiff("s", rstCopy![TIMESTAMP], ![TIMESTAMP]) > 3600 Then
    .Edit
    ![Time Difference Seconds] = Null
    .Update
Else
    .Edit
    ![Time Difference Seconds] = DateDiff("s", rstCopy![TIMESTAMP], ![TIMESTAMP])
    .Update
End If

If ![OWPFID] <> rstCopy![OWPFID] Then
    If ![OWPPCK] <> rstCopy![OWPPCK] Then
    Else
        .Edit
        ![NewLocation] = True
        .Update
    End If
End If

End With

rst.MoveNext
rstCopy.MoveNext

Counter = Counter - 1

Wend

rst.Close
rstCopy.Close

似乎在这个阶段发生了错误

    Else
       .Edit
       ![Time Difference Seconds] = DateDiff("s", rstCopy![TIMESTAMP], ![TIMESTAMP])
       .Update
    End If
4

1 回答 1

1

不确定,但似乎像您正在比较两个记录集的记录会导致问题。它不应该,但我们并不生活在一个完美的世界中。

您尝试完成的工作应该足够容易,只需使用一个记录集即可执行。只需在执行 movenext 之前将先前的记录存储在变量中......然后与当前记录进行比较。我已经发布了我认为可行的代码。

注意:1)我还将字段存储在当前记录集中您正在比较的变量中,以使代码更易于阅读,并且......如果您稍后参考这些字段值,它应该加快速度没有为相同的值多次点击记录集(或者,我认为。) 2)当前记录变量的前缀为“This ...”,以前的记录变量的前缀为“Prev ...” 3)我使用了一个“Do until ... Loop”而不是“While ... wend”,因为那是我的编程风格。

希望它有效。这里是:

Sub DoIt
    Dim rst As DAO.Recordset
    Dim ThisOWPPK, PrevOWPPK
    Dim ThisJustDate, PrevJustDate
    Dim ThisTIMESTAMP, PrevTIMESTAMP
    Tim ThisOWPFID, PrevOWPFID

    Set rst = dbs.openrecordset("SELECT * FROM [Qry_Calculate_Picking_Times]", dbopendynaset)

    rst.MoveFirst

    Do Until rst.EOF
        PrevOWPPCK = ![OWPPCK]
        PrevJUSTDate = ![JustDate]
        PrevTIMESTAMP = ![TIMESTAMP]
        PrevOWPFID = ![OWPDIF]

        rst.MoveNext
        ThisOWPPCK = ![OWPPCK]
        ThisJUSTDate = ![JustDate]
        ThisTIMESTAMP = ![TIMESTAMP]
        ThisOWPFID = ![OWPDIF]

        If ThisOWPPCK <> PrevOWPPCK Or ThisJustDate <> PrevJustDate Or DateDiff("s", PrevTIMESTAMP, ThisTIMESTAMP) > 3600 Then
            .Edit
            ![Time Difference Seconds] = Null
            .Update
        Else
            .Edit
            ![Time Difference Seconds] = DateDiff("s", PrevTIMESTAMP, ThisTIMESTAMP)
            .Update
            End If

            If ThisOWPFID <> PrevOWPFID Then
            If ThisOWPPCK <> PrevOWPPCK Then
                Else
                    .Edit
                    ![NewLocation] = True
                    .Update
            End If
        End If

    Loop

End Sub
于 2014-02-05T01:03:54.377 回答