我已经在Access 2010数据库中使用ADO函数CheckInvTotals
5年了,没有出现任何问题。最近我已迁移到Office 2019,并且此功能无法返回以下消息:
错误-2147024882(没有足够的内存资源来完成此操作。)
我可以绕过启动表单来测试此功能。以这种方式执行功能仍然会失败,并出现上述错误,因此其他正在运行的对象不太可能引起内存泄漏。
我引用了Microsoft ActiveX Data Objects 6.1 Library
。
我想知道为什么ADO会失败,并收到有关如何消除ADO例程中的错误的建议。
CheckInvTotals2
正常运行Public Function CheckInvTotals(lngPayID As Long) As Boolean
'Is there a difference between Invoice Total and payment amount
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
On Error GoTo CheckInvTotals_Error
With cmd
.CommandText = "qryprmInvDiff"
.CommandType = adCmdStoredProc
Set .ActiveConnection = CurrentProject.Connection
.Parameters.Append .CreateParameter("PayID", adBigInt, adParamInput, , lngPayID)
rst.CursorType = adOpenStatic
Set rst = .Execute
End With
CheckInvTotals = rst.EOF
rst.Close
CheckInvTotals_Error:
If Err Then
MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
End If
Set rst = Nothing
Set cmd = Nothing
End Function
Public Function CheckInvTotals2(lngPayID As Long) As Boolean
'Is there a difference between Invoice Total and payment amount
Dim db As Database
Dim qd As DAO.QueryDef
Dim prmPayID As DAO.Parameter
Dim rst As DAO.Recordset
On Error GoTo Handle_err
Set db = CurrentDb
Set qd = db.QueryDefs("qryprmInvDiff")
Set prmPayID = qd.Parameters!PayID
prmPayID.Value = lngPayID
Set rst = qd.OpenRecordset
CheckInvTotals2 = rst.EOF
rst.Close
Handle_err:
If Err Then
MsgBox "Error " & Format(Err.Number) & " " & Err.Description
Err.Clear
End If
On Error Resume Next
Set rst = Nothing
Set prmPayID = Nothing
Set qd = Nothing
Set db = Nothing
End Function
SQL qryprmInvDiff
:
PARAMETERS PayID Long;
SELECT Creditors.CName, Creditors.Code, [InvTotal]-[Amount] AS Diff FROM
Creditors INNER JOIN (Payments INNER JOIN qryPayInvTotal ON
Payments.ID = qryPayInvTotal.PayID) ON Creditors.ID = Payments.CID
WHERE ((([InvTotal]-[Amount])<>0) AND ((Payments.PID)=[PayID]));
代码应仅返回true
或false
。
答案 0 :(得分:0)
为时已晚,但今天我遇到了这个问题,也许还有其他一些人...
MS信息:https://docs.microsoft.com/en-us/office/troubleshoot/access/adbigint-data-type-errors
解决方案:将adBigInt更改为更合适的值,以我为例,adNumeric可以完成工作
Set Cmd = New ADODB.Command
RS.MoveFirst
With Cmd
.ActiveConnection = CurrentProject.Connection
.CommandType = adCmdText
.CommandText = strSQL
.Parameters.Append .CreateParameter("@idposition", adChar, adParamInput, 36, strGUID)
.Parameters.Append .CreateParameter("@idbeleg", adChar, adParamInput, 36, RS.Fields("idbeleg"))
' ########### A2019 > adBigInt changed to adNumeric (Database Datatype: Long (Integer))
'.Parameters.Append .CreateParameter("@sortnr", adBigInt, adParamInput, , RS.Fields("sortnr"))
.Parameters.Append .CreateParameter("@sortnr", adNumeric, adParamInput, , RS.Fields("sortnr"))
```