HOW TO
This article shows how to use VBA and ArcObjects to select features based on attribute values in a joined table.
Code:
Sub SelectFeatures()
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pFeatureLayer As IFeatureLayer
Set pFeatureLayer = pMxDoc.FocusMap.Layer(0)
' The Display Table has the joined fields.
Dim pDisplayTable As IDisplayTable
Set pDisplayTable = pFeatureLayer
' Note the syntax for a joined field is table_name.field_name.
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New QueryFilter
pQueryFilter.WhereClause = "tract_pop.POPULATION > 4000"
' Make the selection in the display table.
Dim pSelSet As ISelectionSet
Set pSelSet = pDisplayTable.SelectDisplayTable(pQueryFilter, _
esriSelectionTypeHybrid,esriSelectionOptionNormal, Nothing)
' Apply the selection to the feature class.
Dim pFeatSel As IFeatureSelection
Set pFeatSel = pFeatureLayer
Set pFeatSel.SelectionSet = pSelSet
' Refresh the display.
Dim pActiveView As IActiveView
Set pActiveView = pMxDoc.FocusMap
pActiveView.Refresh
MsgBox pSelSet.count & " features are now selected."
End Sub
Code:
Sub CursorThruFeatures()
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pFeatureLayer As IFeatureLayer
Set pFeatureLayer = pMxDoc.FocusMap.Layer(0)
' The Display Table has the joined fields.
Dim pDisplayTable As IDisplayTable
Set pDisplayTable = pFeatureLayer
' Note the syntax for a joined field is table_name.field_name.
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New QueryFilter
pQueryFilter.WhereClause= _
"tract_pop.POPULATION > 4000"
' Make the cursor from the display table.
Dim pFeatCursor As IFeatureCursor
Set pFeatCursor = pDisplayTable.SearchDisplayTable _
(pQueryFilter, False)
' Loop thru the cursor and count the features
Dim pFeat As IFeature
Set pFeat = pFeatCursor.NextFeature
Dim count As Long
Do Until pFeat Is Nothing
count = count + 1
Set pFeat = pFeatCursor.NextFeature
Loop
MsgBox "The cursor has " & count & " features."
End Sub
Get help from ArcGIS experts
Download the Esri Support App