Field Names

R

Roy

Thanks in advance.
This is my code (courtesy Joe Fallon),but this just exports the data
and not the field names.What am I doing wrong?

Range("A20").Select
Set xlWorkSheet = xlWorkBook.Worksheets("GWM_WTD")
iRow = 20
For iCol = 0 To rs.Fields.COUNT - 1
xlWorkSheet.Cells(iRow, 32).Value = rs.Fields(iCol).Name
Next
xlWorkSheet.Range(xlWorkSheet.Cells(iRow, iCol), _
xlWorkSheet.Cells(iRow, rs.Fields.COUNT)).Font.Bold = True

'Do Until rs.EOF
xlWorkSheet.Cells(iRow, 32).CopyFromRecordset rs

The range is..the row starts at 20 and the column starts at 32.

Any help?
 
K

Klatuu

You are writing all the field names to the same cell, then overwriting that
with the recordset.

Set xlWorkSheet = xlWorkBook.Worksheets("GWM_WTD")
iRow = 20
For iCol = 0 To rs.Fields.COUNT - 1
With xlWorkSheet.Cells(iRow, iCol + 32)
.Value = rs.Fields(iCol).Name
.Font.Bold = True
End With
Next iCol

xlWorkSheet.Cells(iRow + 1, 32).CopyFromRecordset rs
 
Top