By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,037 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,037 IT Pros & Developers. It's quick & easy.

How to retrieve column names in a table

P: n/a
How can I retrieve just the column names from an Access table. I don't
need the data, just the column names.
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"John T. McCraw" <jo*********@netzero.com> wrote in message
news:dd************************@posting.google.com ...
How can I retrieve just the column names from an Access table. I don't
need the data, just the column names.

Nov 13 '05 #2

P: n/a
jo*********@netzero.com (John T. McCraw) wrote in message news:<dd************************@posting.google.co m>...
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
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.