Click to See Complete Forum and Search --> : Getting metadata from Access database
Mort101
Oct 4th, 2000, 06:18 AM
I have an Access 97 database, and I need to get the column names from a specific table and use these as headings in a listview control. Can this be done through the data control in VB or do I need to use some kind of SQL statement?
Even just an example on how to get metadata from an access database would be great.
Thanks
gnosys
Oct 5th, 2000, 02:05 PM
I think this would work:
Dim db as Database
Dim tDef as TableDef
dim i as Integer
dim arrColumnNames() as String
Set db = OpenDatabase("c:\databases\somedatabase.mdb")
Set tDef = db.Tabledefs("NameOfYourTable")
Redim arrColumnNames(0 to tdef.fields.count)
For i = 0 to tdef.fields.count
arrColumnNames(i)=tDef.Fields(i).Name
Next i
Set tdef = Nothing
Set db = Nothing
That's the DAO way to do it. You could also do it using
ADO(X), but I still find DAO easier to work with for
Access databases. Just old-fashioned I guess. Hope this
helps.
G.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.