Does anybody have any code to check which filelds are keyed?
Any help much appreaciated
Does anybody have any code to check which filelds are keyed?
Any help much appreaciated

This month, every Windows Secrets subscriber can download a one-chapter excerpt of Windows 7: The Missing Manual.Windows 7: The Missing Manual provides valuable information to help you overcome these difficulties in learning a new operating system. Subscribe today to download your free excerpt.
You can use Tools | Analyze | Documenter to produce a report documenting your database. If you click Options in the Tables tab, you can specify which information about indexes (keys) is included.
Here is some code that will list all indexes and their fields in the Immediate window. You can adapt the code to your needs. The code requires a reference (in Tools | References...) to the Microsoft DAO 3.6 Object Library.
Sub ListIndexes()
Dim dbs As DAO.Database
Dim tbl As DAO.TableDef
Dim idx As DAO.Index
Dim fld As DAO.Field
Set dbs = CurrentDb
For Each tbl In dbs.TableDefs
If Left(tbl.Name, 4) <> "MSys" Then
Debug.Print tbl.Name
For Each idx In tbl.Indexes
Debug.Print vbTab & idx.Name & IIf(idx.Primary, " *", "")
For Each fld In idx.Fields
Debug.Print vbTab & vbTab & fld.Name
Next fld
Next idx
End If
Next tbl
Set fld = Nothing
Set idx = Nothing
Set tbl = Nothing
Set dbs = Nothing
End Sub