[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 958
  • Last Modified:

List of Table indexes in MS Access

I would like to create a list of Tables in an Access database along with all of the indexes for each table.  Is there a way to do this?
0
dsoderstrom
Asked:
dsoderstrom
1 Solution
 
therealmongooseCommented:
You can do this using the database analyser Tools>Analyse>documenter
0
 
Steve DubyoCommented:
The following VBA function will return a list of tables and their indexes..

Function GetTablesAndIndexes() As String
    Dim db As Database
    Dim tds As TableDefs
    Dim td As TableDef
    Dim idx As Index
    Dim s As String
   
    Set db = CurrentDb
    Set tds = db.TableDefs
    For Each td In tds
         s = s & td.Name & vbCr
        For Each idx In td.Indexes
            s = s & "  " + idx.Name & vbCr
        Next
    Next    
    GetTablesAndIndexes = s    
End Function

Which can be used like..

Sub Test()
    Debug.Print GetTablesAndIndexes()
End Sub


0
 
RgGray3Commented:

Sub IndexObjectX(tblName As String)
 
   Dim dbs As Database
   Dim tdf As TableDef
   Dim idxLoop As Index
 
   Set dbs = CurrentDb()
   Set tdf = dbs(tblName)
   
   With tdf
      ' Create new index, create and append Field
      ' objects to its Fields collection.
 
      Debug.Print .Indexes.Count & " Indexes in " & .Name & " TableDef"
 
      ' Enumerate Indexes collection of Employees
      ' table.
      For Each idxLoop In .Indexes
         Debug.Print "  " & idxLoop.Name
      Next idxLoop
 
   End With
   
   dbs.Close
    Set tdf = Nothing
    Set dbs = Nothing
End Sub

Open in new window

0
 
RgGray3Commented:
Sorry...  hit send before I was ready
And it looks as if influenz has it covered...  but ...



Sub ListAllTablesAndIndexes()
 
Dim dbs As Database
Dim tdf As TableDef
Dim idxLoop As Index
Dim objTmp As Object
 
On Error GoTo ErrTrap
 
   Set dbs = CurrentDb()
   
    For Each objTmp In dbs.TableDefs
        Set tdf = objTmp
        With tdf
           Debug.Print .Indexes.Count & " Indexes in >>  " & .Name
        
           ' Enumerate Indexes collection of table.
           For Each idxLoop In .Indexes
              Debug.Print "  " & idxLoop.Name
           Next idxLoop
        
        
        End With
ResumeForLoop:
        Debug.Print "---------------------------------------------------"
    Next objTmp
On Error Resume Next
    dbs.Close
    Set tdf = Nothing
    Set dbs = Nothing
 
    Exit Sub
 
ErrTrap:
    Debug.Print "Error in > " & tdf.Name & vbCrLf & Err.Number & " - " & Err.Description
    Resume ResumeForLoop
 
End Sub

Open in new window

0
 
dsoderstromAuthor Commented:
Thanks for the help.  I tweaked your code slightly to get exactly what I wanted.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now