473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to retrieve column names in a table

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
2 19495
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matthew Cascio | last post by:
My understanding is that using reserved words as column names is allowable as long as they are quoted. I am trying to create a table dynamically with columns defined by the first row of a text...
10
by: Colleyville Alan | last post by:
I am trying to turn a short and fat (63 columns) table into one that is tall and skinny (7 columns). Basically, I am trying to create a "reverse crosstab" using a looping structure in VBA along...
4
by: Scot L. Harris | last post by:
Currently using Postgresql 7.2.4-5.80 with php 4.2.2.-8.0.8 on a redhat 8.0 system. I am writing some php scripts where I want to generate a list of the column names in a particular table that...
2
by: Charleees | last post by:
Hi all, I have a DataGrid with Template Columns..... There are LAbels,Linkbuttons in the Single Row.. I have to set the Constant Column width for those Template Columns in Grid... Wat...
2
by: SueA | last post by:
Can anyone help me with the code to retrieve the name of the table that a control on a form (that's built off a query) refers to? For instance: qryMfrsAndBrands is based on the tables:...
3
by: Tony Marston | last post by:
I am using PHP 4.4.4 with Oracle 10g Express Edition on Windows XP. I am trying to emulate in Oracle the SET datatype in MySQL and the ARRAY datatype in PostgreSQL I have the created a...
5
by: Ken | last post by:
I'm trying to run a loop to capture column property information from a table in my datasource. Can anybody see where this is going wrong? Dim tbl As New DataTable Dim col As DataColumn Dim x...
8
by: RP | last post by:
I want to retrieve column names (Exact field names) of a table. How to do that?
2
by: Deepa koruturu | last post by:
Hi How to Retrieve Table Names And Column Names in perticuler schema using oracle
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.