how to get the name of all the columns in an Access table?

G

Guest

Hi,

Does anyone know how to get the name of all the columns in an Access table? Is there a SQL statement like "SELECT COLUMN_NAME FROM TABLE_NAME" to achieve that?

Thanks in advance!
 
A

Allen Browne

You can retrieve the Name of each Field in the TableDef (DAO). Example:
http://allenbrowne.com/func-06.html

If you prefer to use ADOX, you can loop through the Columns of the Table in
the Catalog.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

jerry way said:
Does anyone know how to get the name of all the columns in an Access
table? Is there a SQL statement like "SELECT COLUMN_NAME FROM TABLE_NAME"
to achieve that?
 
K

Ken Snell

Use VBA code (example below prints the name in Immediate Window; you can
write the names into an array if you wish):

Dim intField As Integer
Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("Table_Name", dbOpenDynaset, dbReadOnly)

For intField = 0 To rst.Fields.Count - 1
Debug.Print rst.Fields(intField).Name
Next intField

rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing

--
Ken Snell
<MS ACCESS MVP>


jerry way said:
Hi,

Does anyone know how to get the name of all the columns in an Access
table? Is there a SQL statement like "SELECT COLUMN_NAME FROM TABLE_NAME"
to achieve that?
 

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