Display a Recordset in Excel

  • Thread starter Thread starter Alex A
  • Start date Start date
A

Alex A

Hey everyone, I just found this board. I wrote some VBA
to query my SQL Server into a recordset, but I don't know
how to display that recordset on my Excel spreadsheet.
The recordset is full, so how do I put that into Excel?
Here is the Last few lines of my code:

'Create Recordset
rstIVSLH.CursorType = adOpenForwardOnly
rstIVSLH.LockType = adLockReadOnly
rstIVSLH.CursorLocation = adUseClient
Set rstIVSLH = conSQLSERVERConnection.Execute(strSQL)

'ActiveSheet.Rows(3) = rstIVSLH.Fields ???????????????????
End Sub
 
Tom, or anyone...
Along with this solution is there a way to return the
Header too, meaning the column names for the rows
returned?
 
Dim TargetRange as Range
set Target.Range = ActiveSheet.Range("A3")
For intColIndex = 0 To rs.Fields.Count - 1 ' the field names
TargetRange.Offset(0, intColIndex). _
Value = rstIVSLH.Fields(intColIndex).Name
Next
TargetRange.Offset(1, 0).CopyFromRecordset _
rstIVSLH ' the recordset data
 
That's awesome man. Thanks again. You have showed me
the way to Yellow Belt in Kung VBA Foo. :}

Take Care,
Alex.
 
Back
Top