HOW TO
Instructions provided describe how to view the field that joins are based on.
Note:
Code in ArcMap Objects > ThisDocument code module will only run in the current map document. To store the code in all map documents, open the Normal.mxt > ThisDocument code module.
Code:
Public Sub ListJnFields()
' Get the map
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMap As IMap
Set pMap = pDoc.FocusMap
' Get the selected layer or table
Dim pSelItem As IUnknown
Set pSelItem = pDoc.SelectedItem
If Not TypeOf pSelItem Is IDisplayTable Then
MsgBox "No Feature layer or table selected"
Exit Sub
End If
' Make sure the selected layer is joined
Dim pDispTable As IDisplayTable
Dim pTable As ITable
Set pDispTable = pSelItem
Set pTable = pDispTable.DisplayTable
If Not TypeOf pTable Is IRelQueryTable Then
MsgBox "The layer or table is not joined"
Exit Sub
End If
' Get the source table of the current join
' object (RelQueryTable)
Dim pRelQTab As IRelQueryTable
Dim pRelClass As IRelationshipClass
Dim pOClass As IObjectClass
Dim strLField As String
Dim strRField As String
Set pRelQTab = pTable
Set pRelClass = pRelQTab.RelationshipClass
Set pOClass = pRelClass.OriginClass
If pRelQTab.SourceTable Is pOClass Then
strLField = pRelClass.OriginPrimaryKey
strRField = pRelClass.OriginForeignKey
Else
strLField = pRelClass.OriginForeignKey
strRField = pRelClass.OriginPrimaryKey
End If
MsgBox "Left table key: " & strLField & vbNewLine & _
"Right table key: " & strRField
End Sub
Get help from ArcGIS experts
Download the Esri Support App