How can i get the tables from an accessdatabase in to a listfield???
Printable View
How can i get the tables from an accessdatabase in to a listfield???
Will this help you? The sample code will list all the available table in a access database as well as all the respective fields.
Code:Dim db As DAO.Database
Dim tbl As DAO.TableDef
Dim fld As DAO.Field
Set db = DAO.OpenDatabase("C:\db3.mdb", False, False)
For Each tbl In db.TableDefs
List1.AddItem tbl.Name
For Each fld In tbl.Fields
List1.AddItem "---" & fld.Name
Set fld = Nothing
Next
Set tbl = Nothing
Next
db.Close
Set db = Nothing
Sorry! I´m new at databaseprogging. How do i define the "DAO.Database"
Dim db As DAO.Database ' <--- user defined type not defined
Dim tbl As DAO.TableDef
Dim fld As DAO.Field
Set db = DAO.OpenDatabase("C:\Program Files\Microsoft Visual Studio\Projekt\Softsheet4\Base.mdb", False, False)
For Each tbl In db.TableDefs
List1.AddItem tbl.Name
For Each fld In tbl.Fields
List1.AddItem "---" & fld.Name
Set fld = Nothing
Next
Set tbl = Nothing
Next
db.Close
Set db = Nothing
Hope on an answer :-)
If you have a data control on your form,
Dim db as Database ' or Public db as Database
if not, you need to make a reference to dao from the references.
Thanx to both!! I got it now... :-)))