English

How To: View the field that a join is based on for a dataset and standalone table

Summary

Instructions provided describe how to view the field that joins are based on.

Procedure

This can be done with a visual basic script. The script only works for the recent join.

  1. Start ArcMap.
  2. Open the Visual Basic Editor.

    In ArcMap, select Tools > Macros > Visual Basic Editor.

  3. In the Project Explorer window, expand Project and select ArcMap Objects > ThisDocument. Right-click ThisDocument and select View Code.
    [O-Image] Visual Basic Project  Explorer
    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.

  4. Copy the following code into the 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

  5. Close the Visual Basic Editor.
  6. Run the code.

    A. Click Tools > Macros > Macros to display the Macros dialog box.
    B. Select a macro and click Run.