copying field headers when exporting data to Excel

A

andrea.bruner

I'm creating a VBA script in Access that will take data selected by a
basic query, place it in an Excel worksheet, and format the data. I
cannot figure out how to take the headers from the fields I select in
the query and place them at the top of the Excel sheet. I do not want
to hardcode the field names, as this script will be reused on various
datasets. Anyone have a suggstion?

Thanks,
Andrea
 
J

John Nurick

Hi Andrea,

If you open a recordset rsR on the query, you can get the field names by
using stuff like this:

Dim j As Long
Dim strFieldName As String

For j = 0 to rsR.Fields.Count - 1
strFieldName = rsR.Fields(j).Name
'do stuff with strFieldName
...
Next
 

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

Top