This ArcCatalog example lists the attribute indexes in a geodatabase, discounting the index on the object ID. You may find this macro useful when receiving the following message after trying to edit a personal geodatabase: 'Could not edit any of the map's layers. Check to see if a layer or table contains a unique index on a user managed column.'
The code also demonstrates how to operate on all the datasets in a geodatabase. For efficiency, name objects are used until it is determined that the dataset should be opened.
How to use
- Paste the code into your ArcCatalog VBA environment.
- Select a geodatabase in either the tree view or contents view and run the ListIndexesInGeodatabase macro. The output will appear in the VBA 'Immediate' window
Public Sub ListIndexesInGeodatabase()
Dim pGxApp As IGxApplication
Set pGxApp = Application
Dim pGxObject As IGxObject
Set pGxObject = pGxApp.SelectedObject
Dim pDatasetName As IDatasetName
If TypeOf pGxObject Is IGxDatabase Then
Debug.Print "Dataset name", "Index name", "Unique?"
Debug.Print "------------", "----------", "-------"
Dim pWorkspace As IWorkspace
Set pWorkspace = pGxObject.InternalObjectName.Open
Call TraverseDatasetNames(pWorkspace.DatasetNames(esriDTAny))
End If
End Sub
Public Sub TraverseDatasetNames(pEnumDatasetName As IEnumDatasetName)
Dim pDatasetName As IDatasetName
Set pDatasetName = pEnumDatasetName.Next
Do Until pDatasetName Is Nothing
If pDatasetName.Type = esriDTFeatureClass _
Or pDatasetName.Type = esriDTTable Then
Call ListIndexes(pDatasetName)
ElseIf pDatasetName.Type = esriDTFeatureDataset Then
Call TraverseDatasetNames(pDatasetName.SubsetNames)
End If
Set pDatasetName = pEnumDatasetName.Next
Loop
End Sub
Public Sub ListIndexes(pDatasetName As IDatasetName)
Dim pClass As IClass
Dim pName As IName
Set pName = pDatasetName
Set pClass = pName.Open
Dim pIndexes As IIndexes
Dim pIndex As IIndex
Dim i As Long
Set pIndexes = pClass.Indexes
For i = 0 To pIndexes.IndexCount - 1
Set pIndex = pIndexes.Index(i)
Dim pFields As IFields
Set pFields = pIndex.Fields
If Not (pFields.Field(0).Type = esriFieldTypeOID _
Or pFields.Field(0).Type = esriFieldTypeGeometry) Then
Debug.Print pDatasetName.Name, pIndex.Name, pIndex.IsUnique
End If
Next i
End Sub