问题:是否存在已知的Access / VBA问题,其中一个获得错误91然后一旦手动继续通过Debug / F5运行代码(不更改任何内容),错误不再出现?
这是一个大型项目,我不确定导致此错误的原因。我知道不是一个未设置的变量,因为我只得到一次错误。这是场景:
重现的步骤:
行为:
我不确定这是否相关,但这是调试器带我的代码行,以及它调用的函数:
If Not DBUpdate(strSQL, Application.VBE.ActiveCodePane.CodeModule, "DBLocked", "") Then Exit Function
Public Function DBUpdate(str_SQL As String, str_Module As String, Optional str_Function As String, Optional str_ErrorDetails As String) As Boolean
Dim booDBUpdateFail As Boolean
Dim intFailCount As Integer
DBUpdate = True 'assume success
intFailCount = 0
On Error GoTo DBUpdateError
Do
booDBUpdateFail = False
db.Execute str_SQL, dbFailOnError
Loop Until booDBUpdateFail = False Or intFailCount = P_DBUpdateRetriesOnFailure
If intFailCount = P_DBUpdateRetriesOnFailure Then DBUpdate = False 'return failure
Exit Function
DBUpdateError:
intFailCount = intFailCount + 1
modIO.AppendToDBLog CStr(Now()) & ": " & str_Module & " - ErrorDBExecute - " & str_Function & " - " & str_ErrorDetails & " - TryCount: " & CStr(intFailCount)
booDBUpdateFail = True
Wait P_DBUpdateRetryIntervalSeconds * 1000 'wait
Resume Next
End Function
注意:上面的DB是由应用程序启动时启动的隐藏表单的On Load事件实例化的公共对象。初始化子:
Public Sub InitPublic()
If db Is Nothing Then Set db = CurrentDb() 'Open connection to current Access database
If UserPerm Is Nothing Then Set UserPerm = New clsUserPerm
If wfstatus Is Nothing Then Set wfstatus = New clsWFStatus
If Log Is Nothing Then Set Log = New clsLog
If PurchaseLevels Is Nothing Then Set PurchaseLevels = New clsPurchasingLevels
If objPrintTemplate Is Nothing Then Set objPrintTemplate = New clsPrintTemplate
If objPrintReport Is Nothing Then Set objPrintReport = New clsPrintTemplate
End Sub