Extracting Table Column Names

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

Hi,
Is there a way to query column names in a table and store the column names
in another table?
Thanks,
Ron
 
Ron,

This is more than you asked for but you can easily modify it to suit your
exact needs. The code below lists all the fields of each table in your db.
With minor tweak you can change it to take an input variable, the table you
wish to analyze, to only get the info pertaining to 1 table.

Function listTableFields() As String
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim tdfld As DAO.TableDef
Dim fld As Field
Dim output As String

Set db = CurrentDb()
For Each tdf In db.TableDefs 'loop through all the tables
output = output & vbCrLf & "Table Name: " & tdf.Name
Set tdfld = db.TableDefs(tdf.Name)
For Each fld In tdfld.Fields 'loop through all the fields of the
tables
output = output & vbCrLf & vbTab & vbTab & vbTab & vbTab &
fld.Name
Next
output = output & vbCrLf
Next tdf

listTableFields = output

End Function
 
Back
Top