Option #1 - Hardwired Definition Query
Code:
Public Sub DefQUpdate_HardWired()
Dim pMxd As IMxDocument
Set pMxd = ThisDocument
Dim pMap As IMap
Set pMap = pMxd.FocusMap
Dim i As Integer
Dim pFlyr As IFeatureLayer, pFlyrDef As IFeatureLayerDefinition
For i = 0 To pMap.LayerCount - 0
Set pFlyr = pMap.Layer(i)
Set pFlyrDef = pFlyr
pFlyrDef.DefinitionExpression = "REGION_FIELD = 'FieldValue'"
Next i
pMxd.ActiveView.Refresh
End Sub
Option #2 - User-defined
In the code below; you will need a common field in each layer, otherwise the definition query will be invalid and the layer will not draw.
- From the Customize dialog create and add UIComboboxControl
- Copy and Paste code sample into VBA Editor
- Use ComboBox control to update the Definition Query for all Layers in the active map
Code:
Private Function MxDocument_OpenDocument() As Boolean
'Populate Combobox
UIComboBoxControl1.AddItem "OBJECTID IS NOT NULL", 0
UIComboBoxControl1.AddItem "OBJECTID > 2", 1
UIComboBoxControl1.AddItem "OBJECTID > 4", 2
UIComboBoxControl1.AddItem "OBJECTID > 6", 3
End Function
Private Sub UIComboBoxControl1_SelectionChange(ByVal newIndex As Long)
Dim pMxd As IMxDocument
Dim pMap As IMap
Set pMxd = ThisDocument
Set pMap = pMxd.FocusMap
Dim pFlyr As IFeatureLayer, pFlyrDef As IFeatureLayerDefinition
Dim pDisplayExp As String
'Get Selected Definition Query from Combobox
pDisplayExp = UIComboBoxControl1.Item(newIndex)
Dim i As Integer
i = 0
'Iterate layers in map and set Definition Query
For i = 0 To pMap.LayerCount - 1
Set pFlyr = pMap.Layer(i)
Set pFlyrDef = pFlyr
pFlyrDef.DefinitionExpression = pDisplayExp
Next i
pMxd.ActiveView.Refresh
End Sub
Bookmarks