parsingADOlogging集到单独的Excel表格

我试图采取一个ADOlogging集,然后循环通过它parsing到Excel工作簿内的不同工作表的单个行。 不幸的是,当我通过我的代码,我得到以下错误:运行时错误“13”:types不匹配。 当我在我的代码中调用sub时会发生这种情况 – 它从来没有实际进入到subprocess中。 我想知道如果我不正确地传递logging集,或者如果它是我的循环内某处的问题。

无论如何,这是我的代码 – 任何帮助,非常感谢!

Sub SplitData(ByVal rs As ADODB.Recordset) ' Instantiate count variables for each result type ' Start at 2 to give room for Table headers on sheets Dim NewAppsCount, BadLogCount, MatNotesCount, ZeroBalCount As Integer NewAppsCount , BadLogCount, MatNotesCount, ZeroBalCount = 2 ' Row Counter Dim Count As Long Count = 0 ' Loop through the recordset and parse rows to appropriate worksheets Do While Not rs.EOF If CStr(rs.Fields("Maturity Date")) = "" Then If CStr(rs.Fields("Log_Date")) = "" Then ' Applications that have not been properly logged Sheet4.Range("A" & CStr(BadLogCount)) = rs.Fields(Count).Value Count = Count + 1 BadLogCount = BadLogCount + 1 Else ' New Applications Sheet6.Range("A" & CStr(NewAppsCount)) = rs.Fields(Count).Value Count = Count + 1 NewAppsCount = NewAppsCount + 1 End If Else If Month(rs.Fields("Maturity Date")) < Month(Date) Then ' Maturing Notes with Zero Outstanding Balance Sheet7.Range("A" & CStr(ZeroBalCount)) = rs.Fields(Count).Value Count = Count + 1 ZeroBalCount = ZeroBalCount + 1 Else ' Maturing Notes Sheet8.Range("A" & CStr(MatNotesCount)) = rs.Fields(Count).Value Count = Count + 1 MatNotesCount = MatNotesCount + 1 End If End If rs.MoveNext Loop End Sub 

这里是调用GetData的子:

 Sub GetData(ByVal Update As Boolean) Dim conn As ADODB.Connection Dim rs As ADODB.Recordset Dim query As String Dim path As String Dim prompt, result As Integer Dim day, today As String ' ...skipping stuff not related to the issue... ' Set the UNC Path path = "\\this\is\the\path" ' Instantiate ADO Objects Set conn = New ADODB.Connection Set rs = New ADODB.Recordset ' Connect to data source conn.Open "Provider=Microsost.JET.OLEDB.4.0;Data Source=" & path & ";" ' The Query query = "This is a big 'ol query that I won't repost here" 'Run the query and populate the Recordset object rs.CursorLocation = adUseClient rs.Open query, conn, adOpenStatic, adLockReadOnly 'Parse contetns of Recordset to worksheet Application.ScreenUpdating = False Me.SplitData(rs) 'Close the ADO Objects, set them to null, and exit sub rs.Close conn.Close Set rs = Nothing Set conn = Nothing Exit Sub End Sub 

尝试改变:

 Me.SplitData(rs) 

至:

 Me.SplitData rs 

不必要的括号往往会在VBA中造成问题。

(NB我假设这两个Sub显示在Me有道理的上下文 – 例如类模块, ThisWorkbook模块,工作表模块,支持UserForm等)