How to address the column names of a table (1 Viewer)

exaccess

Registered User.
Local time
Today, 10:52
Joined
Apr 21, 2013
Messages
287
I have a table, whıch is created by using the Docmd.Transfertext procedure that takes the first row of the input csv file as column names of the table. How can I using SQL and VBA find the names of these columns so that I can use them in a query.
 

MarkK

bit cruncher
Local time
Today, 02:52
Joined
Mar 17, 2004
Messages
8,178
In DAO, a TableDef, QueryDef, and Recordset all expose a Fields collection, which you can enumerate using code like . . .
Code:
Sub Test10934912()
    Dim dbs As DAO.Database
    Dim fld As DAO.Field
    
    Set dbs = CurrentDb
    With dbs.TableDefs("tYourTable")  [COLOR="Green"] 'open the tabledef[/COLOR]
        For Each fld In .Fields    [COLOR="Green"] 'enumerate its fields collection[/COLOR]
            Debug.Print fld.Name    [COLOR="Green"]'print each field name[/COLOR]
        Next
    End With
    
End Sub
 

exaccess

Registered User.
Local time
Today, 10:52
Joined
Apr 21, 2013
Messages
287
In DAO, a TableDef, QueryDef, and Recordset all expose a Fields collection, which you can enumerate using code like . . .
Code:
Sub Test10934912()
    Dim dbs As DAO.Database
    Dim fld As DAO.Field
    
    Set dbs = CurrentDb
    With dbs.TableDefs("tYourTable")  [COLOR="Green"] 'open the tabledef[/COLOR]
        For Each fld In .Fields    [COLOR="Green"] 'enumerate its fields collection[/COLOR]
            Debug.Print fld.Name    [COLOR="Green"]'print each field name[/COLOR]
        Next
    End With
    
End Sub
Worked like charmingly. Thanks a lot.
 

Users who are viewing this thread

Top Bottom