Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving all field names in a recordset 1

Status
Not open for further replies.

ejsmith

IS-IT--Management
Aug 5, 2001
39
US
I'm working on sending the results of a recordset to Excel - in my effort to do this I've found a lot of repetition when sending the results to the cells... I'm currently sending one recordset column at a time like so:
X.activecell.Offset(row, col).Value = rs![ColumnNameHere]

What I'd like to do is just pass the recordset name to a subroutine - in order to do that and send all of the columns to Excel I need a list of all of the fields in the recordset.
I know I've seen this done before - but I'm having a brainfreeze and I can't seem to find examples on Msdn.
I'd appreciate any help/suggestions you can give!
Thanks!
 
Dim dbs as database
Dim rst as recordset
Set dbs = currentdb()
Set rst = dbs.openrecordset("YourSource")
For i = 0 to rst.fields.count
msgbox rst.fields(i).name' Or whatever you're gonna do here
next i
Set rst = nothing
Set dbs = nothing
End sub
 
Thanks DatabaseGuy - that did the trick!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top