A primary key is simply an index, and an index can contain up to ten
separate fields. The following code will go through all the tables in your
application and print the details for the primary key of each one:
Sub PrimaryKeyDetails()
Dim dbCurr As DAO.Database
Dim tdfCurr As DAO.TableDef
Dim idxCurr As DAO.Index
Dim fldCurr As DAO.Field
Set dbCurr = CurrentDb()
For Each tdfCurr In dbCurr.TableDefs
If (tdfCurr.Attributes And dbSystemObject) = 0 Then
For Each idxCurr In tdfCurr.Indexes
If idxCurr.Primary = True Then
Debug.Print "Table " & tdfCurr.Name & _
" has Primary Key " & idxCurr.Name & _
" which contains the following fields:"
For Each fldCurr In idxCurr.Fields
Debug.Print " " & fldCurr.Name
Next fldCurr
Debug.Print ""
End If
Next idxCurr
End If
Next tdfCurr
Set dbCurr = Nothing
End Sub