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.
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
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