List Table Field Names In Another Table

  • Thread starter Thread starter Bob Barnes
  • Start date Start date
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
 
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
 
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
 
Back
Top