VB Code:
  1. Option Explicit
  2.  
  3. Dim cnTables As ADODB.Connection
  4. Dim rsTables As ADODB.Recordset
  5. Dim rsFields As ADODB.Recordset
  6. Dim strCn As String
  7. Dim strSQL As String
  8. Dim i As Integer
  9.  
  10. 'Requires ADO reference
  11. 'Written by Carl R. Armbruster
  12. 'Free to use - it's yours!
  13.  
  14. Private Sub Form_Load()
  15.     'database connnection string
  16.     strCn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  17.             "Persist Security Info=False;" & _
  18.             "Data Source=" & App.Path & "\Northwind.mdb"
  19. End Sub
  20. Private Sub Command1_Click()
  21.     'recordset of field names
  22.     Set rsFields = New ADODB.Recordset
  23.     'connection to recieve tabel schema
  24.     Set cnTables = New ADODB.Connection
  25.     'open connection
  26.     cnTables.Open strCn
  27.    
  28.     'get table schema
  29.     Set rsTables = cnTables.OpenSchema(adSchemaTables)
  30.     'loop through table recordset
  31.     Do While Not rsTables.EOF
  32.         'only get the tables (table schema also retrieves views)
  33.         If rsTables!TABLE_TYPE = "TABLE" Then
  34.             'get an empty recordset(1 never equals 2!)
  35.             strSQL = "SELECT * FROM [" & rsTables!TABLE_NAME & "] WHERE 1 = 2"
  36.             rsFields.Open strSQL, strCn, adOpenStatic, adLockReadOnly
  37.             'loop through the field collection
  38.             For i = 0 To rsFields.Fields.Count - 1
  39.                 Debug.Print "Table: " & rsTables!TABLE_NAME & "; Field: " & rsFields.Fields(i).Name
  40.             Next i
  41.             rsFields.Close
  42.         End If
  43.         rsTables.MoveNext
  44.     Loop
  45.    
  46.     'close and cleanup
  47.     rsTables.Close
  48.     Set rsTables = Nothing
  49.    
  50.     cnTables.Close
  51.     Set cnTables = Nothing
  52.    
  53.     Set rsFields = Nothing
  54. End Sub