HOW TO
This article contains sample code that lists the names of all relates for the first layer displayed in the table of contents in ArcMap.
Note:
Code in ThisDocument code module will only run in the current map document. To store the code in all map documents, open the code in the Normal.mxt ThisDocument code module.
Code:
Sub GetLayer()
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMap As IMap
Set pMap = pDoc.FocusMap
Dim pLayer As IFeatureLayer
Set pLayer = pMap.Layer(0)
ListRelates pLayer
End Sub
Sub ListRelates(pFLayer As IFeatureLayer)
Dim pRelClassColl As IRelationshipClassCollection
Set pRelClassColl = pFLayer
Dim pEnumRelClass As IEnumRelationshipClass
Dim pRelClass As IRelationshipClass
Set pEnumRelClass = pRelClassColl.RelationshipClasses
Dim pDs As IDataset
Set pRelClass = pEnumRelClass.Next
Do Until pRelClass Is Nothing
'List the name of the relate
Set pDs = pRelClass
MsgBox pDs.Name
Set pRelClass = pEnumRelClass.Next
Loop
End Sub
Article ID:000004973
Get help from ArcGIS experts
Download the Esri Support App