columns in a table

Jacob Mathai

Registered User.
Local time
Today, 10:10
Joined
Sep 6, 2001
Messages
546
How can I programatically find the names of all columns in a table?

Thanks in advance.
 
You can get a name (and other attributes) of a column with a property of Fields.

rst.Fields(x).Name
rst.Fields(x).FieldSize
rst.Fields(x).Size
rst.Fields(x).Type

x being any interger. 0 (zero) represents is the first field/column.

Here is one link that may give you more detail.
 
I use this:

Function listfields(strTableName As String) As String
Dim db As Database
Dim rs As Recordset
Dim strSQL As String
Dim Field As Field
Set db = CurrentDb
strSQL = "SELECT * FROM " & strTableName
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
For Each Field In rs.Fields
listfields = Field.Name 'You can send to an array or another table here
Next
End Function

Here is a start. You pass the table name to this function. Instead of passing the table name, you could have another For loop that goes through all your tables (skip system tables - there are posts on this site on how to do that.) and list all field names for all your pertinent tables.

Also you could send the name to an array or write to a new table, etc...
What do you need to do with the table names?
 
Last edited:

Users who are viewing this thread

Back
Top Bottom