How can I retrieve just the column names from an Access table. I don't
need the data, just the column names.
Douglas J. Steele - 01 Sep 2004 20:23 GMT
Assuming you've got a reference set to DAO, something like the following
untested air-code will do it:
Sub ListTableFields(TableName As String)
Dim dbCurr As DAO.Database
Dim tdfCurr As DAO.TableDef
Dim fldCurr As DAO.Field
Set dbCurr = CurrentDb()
Set tdfCurr = dbCurr(TableName)
Debug.Print "Fields in table " & tdfCurr.Name
For Each fldCurr In tdfCurr.Fields
Debug.Print fldCurr.Name
Next fldCurr
Set fldCurr = Nothing
Set tdfCurr = Nothing
Set dbCurr = Nothing
End Sub

Signature
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
> How can I retrieve just the column names from an Access table. I don't
> need the data, just the column names.
Pieter Linden - 02 Sep 2004 00:21 GMT
> How can I retrieve just the column names from an Access table. I don't
> need the data, just the column names.
You have to use code. What are you going to use the column names for
(so someone has a clue as to how to answer this in a useful way)?
One way:
Option Explicit
Public Function GetFieldList(ByVal strTable As String) As String
Const cSep As String = ";"
Const cQuote As String = """"
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim strTemp As String
Set db = CurrentDb
Set tdf = db.TableDefs(strTable)
For Each fld In tdf.Fields
If Len(strTemp) = 0 Then
strTemp = cQuote & fld.Name & cQuote
Else
strTemp = strTemp & cSep & cQuote & fld.Name & cQuote
End If
Next fld
GetFieldList = strTemp
Set tdf = Nothing
Set db = Nothing
End Function