超出文件共享锁定计数



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

这是我的代码:

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

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

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

注意:1)我还将字段存储在您正在变量中比较的当前记录集中,以使代码更易于阅读和...如果您稍后参考这些字段值,它应该通过不多次命中相同值的记录集来加快速度(或者我认为是这样。2) 当前记录变量的前缀为"This..."和以前的记录变量前缀为"上一个..."3)我使用了"直到...循环"而不是"虽然...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

最新更新