Reputation: 947
I am trying to iterate through the fields on each recordset and have their values added to my Excel 2007 worksheet.
I have the following code, but I am getting "Object doesn't support this property" whenever it reaches "For Each x In.." Am I missing something ? Do I need to add additional references in VBA to use .Fields? I am currently using Microsoft ActiveX Data Objects 6.0 Library on my references. The SQL queries an Oracle Database, but I don't suppose that matters in this error.
Set recSet = newConn.getOpenIncidents("exampleworkgroup")
Set Path = ThisWorkbook.Worksheets("Incidents")
iRow = 2
With Path
iCol = 1
For Each x In recSet.Fields
.Cells(iRow, iCol).Value = x.Value 'Customer Name
iCol = iCol + 1
Next
End With
And this is the code for the function in my class
Public Function getOpenIncidents(ByVal wrkgp As String)
Set rs = New ADODB.Recordset
Dim SQL As String
SQL = "SELECT intbl.cust_ky, intbl.incid_id, intbl.OPEN_TS, intbl.CLOSE_TS, wrkgptbl.wrkgp_id, intbl.incid_ttl_dn " _
& "FROM (MAIN.testtable intbl INNER JOIN MAIN.wrkgrp wrkgptbl ON intbl.curr_wrkgp_ky=wrkgptbl.wrkgp_ky) " _
& "WHERE wrkgptbl.wrkgp_id='" & wrkgp & "'"
rs.Open SQL, con, adOpenKeyset
rs.MoveFirst
getOpenIncidents = rs
End Function
Upvotes: 2
Views: 3366
Reputation: 3193
I think I've spotted it! recSet
is actually of type Fields. as such there is no such .Fields
property as .Fields
is a property of a Recordset Object.
The fix should be:
For Each x In recSet
Or change the getOpenIncidents()
method to return a RecordSet (including changing the return line to Set getOpenIncidents = rs
).
Upvotes: 3