|
|
Title | Use ADOX to list the tables in an Access database and give their types in Visual Basic 6 |
Description | This example shows how to use ADOX to list the tables in an Access database and give their types in Visual Basic 6. |
Keywords | ADOX, Access, database, table, table type, Visual Basic 6 |
Categories | Database |
|
|
First add references to:
- Microsoft ActiveX Data Objects 2.6 Library
- Microsoft ADO Ext. 2.6 for DLL and Security
(Or whatever your versions are.)
When you click the List Tables button, the following code executes. It opens the database and uses the ADOX catalog to learn about the database. It loops through the Tables collection adding the table names and types to a ListView control. Note that this collection includes tables that you build (TABLE type), Access tables (ACCESS TABLE type), system tables (SYSTEM TABLE type), and queries (VIEW type).
|
|
Private Sub cmdListTables_Click()
Dim conn As ADODB.Connection
Dim cat As ADOX.Catalog
Dim i As Integer
Dim list_item As ListItem
lvwTables.ListItems.Clear
' Open the connection.
Set conn = New ADODB.Connection
conn.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & _
"Data Source=" & txtDatabase.Text
conn.Open
' Make a catalog for the database.
Set cat = New ADOX.Catalog
Set cat.ActiveConnection = conn
' List the catalog's tables.
For i = 0 To cat.Tables.Count - 1
Set list_item = _
lvwTables.ListItems.Add(Text:=cat.Tables(i).Name)
list_item.SubItems(1) = cat.Tables(i).Type
Next i
conn.Close
End Sub
|
|
|
|
|
|