テーブル結合した結合先のレコードを取得

      2017/12/09

Sub GetRelatedRecord()
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
     
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pMxDoc.FocusMap.Layer(0)    '最上位レイヤを取得
     
    Dim pFeatureClass As IFeatureClass
    Set pFeatureClass = pFeatureLayer.FeatureClass
     
    Dim pDisplayRelationshipClass As IDisplayRelationshipClass
    Set pDisplayRelationshipClass = pFeatureLayer
     
    Dim pRelationshipClass As IRelationshipClass
    Set pRelationshipClass = pDisplayRelationshipClass.RelationshipClass    'テーブル結合されている
     
    Dim pFeature As IFeature
    Set pFeature = pFeatureClass.GetFeature(1)      'OID:1のフィーチャを取得
     
    Dim pObjSet As ISet
    Set pObjSet = pRelationshipClass.GetObjectsRelatedToObject(pFeature)    '元のフィーチャを引数としてリレーション先のフィーチャ群を取得
     
    pObjSet.Reset
     
    Dim pRelFeature As IRow
    Set pRelFeature = pObjSet.Next      'リレーション先のレコードを取得(結合先がフィーチャの場合はIFeatureでキャスト可能)
     
    Debug.Print "Count", pObjSet.Count
    Debug.Print pRelFeature.OID
 
End Sub

 - プログラミング, ArcGIS