List Table Field Names In Another Table

B

Bob Barnes

I am sending Access data to Excel. I want to list the
FieldNames in an Excel Named Range directly above the
data returned by the Access Query & sent to Excel.

Looking for sample code to take the Field Names & use
a For Each to get all the FieldNames & then send to another
Table...then send to Excel.

I tried something like this, but it didn't recognize the
FD.Name. . .

Set Z = CurrentDb
Set AQQ = Z.QueryDefs("Bob")
For Each PM In AQQ.Parameters
PM.Value = Eval(PM.Name)
Next PM
Set RS = AQQ.OpenRecordset()
With RS
If Not .BOF Then
Q = "DELETE * FROM FiveGo;"
Z.Execute Q
For Each FD In RS.Fields
'MsgBox FD.Name ---> FD.Name did not appear

TIA - Bob
 
T

TC

For Each FD In RS.Fields
debug.print FD.Name
Next

should work fine for returning the names of the fields in a recordset, as
long as RS is a recordset object (ie. dim-ed 'as recordset'), and FD is a
field object (ie. dim-ed 'as field').

HTH,
TC
 
B

Bob Barnes

TC - Yes, this works. Thank you.

The code I listed below does work. For some reason, it
didn't work before...& I had...
"long as RS is a recordset object (ie. dim-ed 'as
recordset'), and FD is a field object (ie. dim-ed 'as
field')."

Bob
 

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