English

How To: Programmatically access joined fields using VBA and ArcObjects

Summary

This article describes how to access joined fields of a feature layer. Joined fields are contained in the display table.

Procedure

  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.mxt and select ArcMap Objects > ThisDocument then right-click and select View Code.
    [O-Image] Visual Basic Project  Explorer
    Note:
    Code in ThisDocument module will only run in the current map document. To store the code in all your map documents, open the Normal.mxt ThisDocument code module.

  4. Paste the following code into the code module.

    Code:
    Sub AccessJoinedFields()
    Dim pDoc As IMxDocument
    Set pDoc = ThisDocument
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pDoc.FocusMap.Layer(0)

    Dim pFeat As IFeature
    Set pFeat = pFeatureLayer.FeatureClass.GetFeature(12)
    Dim pTable As ITable
    Dim pDisplayTable As IDisplayTable
    Set pDisplayTable = pFeatureLayer
    Set pTable = pDisplayTable.DisplayTable

    Dim pFields As IFields
    Dim pField As IField
    Set pFields = pTable.Fields
    For i = 0 To pFields.FieldCount - 1
    Debug.Print pFields.Field(i).Name
    Next
    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.