Field Names

  • Thread starter Thread starter Roy
  • Start date Start date
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?
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top