?
Solved

List of Table indexes in MS Access

Posted on 2008-06-19
5
Medium Priority
?
950 Views
Last Modified: 2013-11-27
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
Comment
Question by:dsoderstrom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 10

Expert Comment

by:therealmongoose
ID: 21822857
You can do this using the database analyser Tools>Analyse>documenter
0
 
LVL 5

Accepted Solution

by:
Steve Dubyo earned 1000 total points
ID: 21822954
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
 
LVL 11

Expert Comment

by:RgGray3
ID: 21823143

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
 
LVL 11

Expert Comment

by:RgGray3
ID: 21823411
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
 

Author Closing Comment

by:dsoderstrom
ID: 31468811
Thanks for the help.  I tweaked your code slightly to get exactly what I wanted.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question