I have been using this code below for sometime and do not take credit for writing it myself. Just do not remember where I got it or original author.
Anyways....the code goes to a specific database and creates a list of tables and queries in the .mdb in cells A2&B2 going down.
I want to add additional information goes horizontal for each table or query. For tables I would like the list of field names and for queries I would like the list of field names and tables associated.
I thought I had done this several years ago, but I can not see my older posts and I can not find the original spreadsheet. Any thoughts or suggestions would be greatly appreciated.
Kurt
Anyways....the code goes to a specific database and creates a list of tables and queries in the .mdb in cells A2&B2 going down.
I want to add additional information goes horizontal for each table or query. For tables I would like the list of field names and for queries I would like the list of field names and tables associated.
I thought I had done this several years ago, but I can not see my older posts and I can not find the original spreadsheet. Any thoughts or suggestions would be greatly appreciated.
Kurt
Code:
Option Explicit
Public Sub Example()
EnumerateDBTables Range("A1:A2"), "S:\Production Control\Warehouse_Database\Query_Master.mdb"
End Sub
Public Sub EnumerateDBTables(ByVal target As Excel.Range, ByVal dbPath As _
String, Optional ByVal clearSheet As Boolean = True)
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim ws As Excel.Worksheet
Dim lngRow As Long
Dim lngCol As Long
Dim i As Long
Set ws = target.Parent
If clearSheet Then ws.UsedRange.Clear
Set cat = New ADOX.Catalog
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
dbPath
ws.Range(target.Cells(1, 1), target.Cells(1, 1).Offset(0, 1)) = _
Array("Name", "Type")
lngRow = target.Row + 1&
For Each tbl In cat.Tables
If tbl.Type <> "ACCESS TABLE" And tbl.Type <> "SYSTEM TABLE" Then
lngCol = target.Column
ws.Cells(lngRow, lngCol) = tbl.Name
ws.Cells(lngRow, lngCol + 1&) = tbl.Type
'* add loop here
lngRow = lngRow + 1&
End If
Next
ws.UsedRange.Columns.AutoFit
End Sub