【问题标题】:File sharing lock count exceeded超出文件共享锁定计数
【发布时间】:2014-02-05 09:03:54
【问题描述】:

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

这是我的代码:

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

【问题讨论】:

  • 你在这里看到Method 2了吗? support.microsoft.com/kb/815281
  • @SiddharthRout 感谢您的回复,我确实看到用户可以手动覆盖它,但我希望他们不必这样做。如果记录集超过一定限制,有没有办法以编程方式添加它?

标签: vba ms-access


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多