MS Access Database Tables and Fields

This is how to list all LINKED Tables and Fields in an MS Access Database.
To list Local Tables, remove Len(tdfCurrent.Connect) > 0

Public Sub ListTablesAndFields()
    Dim fld As DAO.Field
    Dim tdfCurrent As DAO.TableDef
    Dim dbCurrent As DAO.Database
    
    Set dbCurrent = CurrentDb
    
    Dim fs As Object
    Dim output As Object
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set output = fs.CreateTextFile("c:\Tables_Views_And_Fields.txt", True)
    
    For Each tdfCurrent In dbCurrent.TableDefs
        If Len(tdfCurrent.Connect) > 0 And Left(tdfCurrent.Name, 4) <> "~TMP" Then
            output.WriteLine tdfCurrent.Name
            For Each fld In tdfCurrent.Fields
                output.WriteLine "   " & fld.Name
            Next
            output.WriteLine
        End If
    Next
End Sub
Comments are closed