View Full Version : Get column names from table


thepatrik
02-21-2007, 11:48 PM
Hi!
Can I do a select query in order to get all the column names from a certain table in access?

namliam
02-22-2007, 12:59 AM
You could try going thru the system tables (turn them to visible by going thru Tools=> Options => View => System Objects), note that use of these tables is not supported by M$

Or you can do it thru code: Currentdb.Tabledefs("TableName").Fields(0).Name
this will return the name of the first column in table "TableName", so you have to change the 0 to 1 to get field #2, it is what they call a "zero based array", meaning 0 is 1 and 1 is 2 etc....

I hope this helps...

Dennisk
02-22-2007, 12:59 AM
This is one to get the field names

Private Sub Columns()
Dim fld As Field
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("table1")


For Each fld In rst.Fields
Debug.Print fld.Name
Next
End Sub

thepatrik
02-23-2007, 12:44 AM
Thank you for your answers!