Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / September 2004

Tip: Looking for answers? Try searching our database.

How to retrieve column names in a table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John T. McCraw - 01 Sep 2004 19:59 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.