无法将 ADODB.Recordset 作为参数传递给函数调用
Unable to Pass ADODB.Recordset as a parameter to a function call
以下是我的记录集声明
Dim expectedRs, actualRs As ADODB.Recordset
Set expectedRs = accessDatabse.getResultSetForSqlQuery(tempArr(1))
Set actualRs = accessDatabse.getResultSetForSqlQuery(tempArr(2))
以下工作正常,
excelFunc.writeQueryResultsToExcel( tempArr(0), accessDatabse.getResultSetForSqlQuery(tempArr(1)), accessDatabse.getResultSetForSqlQuery(tempArr(2)))
但是,我无法在方法调用中传递变量
excelFunc.writeQueryResultsToExcel CStr(tempArr(0)), expectedRs,actualRs
我遇到编译时错误"ByRef Argument Type Mismatch"
以下是我的函数被调用
Public Function writeQueryResultsToExcel(workbookName As String, expectedRs As Object, actualRs As Object)
Dim wkb As Workbook
Dim strPath As String
strPath = globalObj.getDefaultRunInstancePath()
Set wkb = Workbooks.Open(strPath + workbookName + ".xlsx")
'rs.Open strSQL
'Sheet4.Range("A1").CopyFromRecordset rs
'***********************************UntestedCode******************************
wkb.Sheets("Expected").Range("A1").CopyFromRecordset expectedRs
wkb.Sheets("Actual").Range("A1").CopyFromRecordset actualRs
wkb.Save
wkb.Close
'***********************************UntestedCode******************************
End Function
Dim expectedRs, actualRs As ADODB.Recordset
实际意思是:
Dim expectedRs As Variant, actualRs As ADODB.Recordset
并且您的函数期望 expectedRs
为 Object
并且 actualRs
也为 Object
。因此进行以下更改:
Dim expectedRs, actualRs As ADODB.Recordset
更改为:
Dim expectedRs As ADODB.Recordset, actualRs As ADODB.Recordset
和
Public Function writeQueryResultsToExcel(workbookName As String, expectedRs As Object, actualRs As Object)
更改为:
Public Function writeQueryResultsToExcel(workbookName As String, expectedRs As ADODB.Recordset, actualRs As ADODB.Recordset)
以下是我的记录集声明
Dim expectedRs, actualRs As ADODB.Recordset
Set expectedRs = accessDatabse.getResultSetForSqlQuery(tempArr(1))
Set actualRs = accessDatabse.getResultSetForSqlQuery(tempArr(2))
以下工作正常,
excelFunc.writeQueryResultsToExcel( tempArr(0), accessDatabse.getResultSetForSqlQuery(tempArr(1)), accessDatabse.getResultSetForSqlQuery(tempArr(2)))
但是,我无法在方法调用中传递变量
excelFunc.writeQueryResultsToExcel CStr(tempArr(0)), expectedRs,actualRs
我遇到编译时错误"ByRef Argument Type Mismatch"
以下是我的函数被调用
Public Function writeQueryResultsToExcel(workbookName As String, expectedRs As Object, actualRs As Object)
Dim wkb As Workbook
Dim strPath As String
strPath = globalObj.getDefaultRunInstancePath()
Set wkb = Workbooks.Open(strPath + workbookName + ".xlsx")
'rs.Open strSQL
'Sheet4.Range("A1").CopyFromRecordset rs
'***********************************UntestedCode******************************
wkb.Sheets("Expected").Range("A1").CopyFromRecordset expectedRs
wkb.Sheets("Actual").Range("A1").CopyFromRecordset actualRs
wkb.Save
wkb.Close
'***********************************UntestedCode******************************
End Function
Dim expectedRs, actualRs As ADODB.Recordset
实际意思是:
Dim expectedRs As Variant, actualRs As ADODB.Recordset
并且您的函数期望 expectedRs
为 Object
并且 actualRs
也为 Object
。因此进行以下更改:
Dim expectedRs, actualRs As ADODB.Recordset
更改为:
Dim expectedRs As ADODB.Recordset, actualRs As ADODB.Recordset
和
Public Function writeQueryResultsToExcel(workbookName As String, expectedRs As Object, actualRs As Object)
更改为:
Public Function writeQueryResultsToExcel(workbookName As String, expectedRs As ADODB.Recordset, actualRs As ADODB.Recordset)