I am tryign this but the code simple changes the color based on a point, line, polygon....I need my code to look at a field and change the symbology baced on the field value...how would I go about modifying this to look at the field value...do I have to build a query?On Error GoTo ErrHand
Dim pApp As IMxApplication
Set pApp = Application
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMap As IMap
Set pMap = pDoc.ActiveView.FocusMap
Dim pFeatLyr As IFeatureLayer
Dim i As Long
' run through the layers and get the first featurelayer
For i = 0 To pMap.LayerCount - 1
If TypeOf pMap.Layer(i) Is IFeatureLayer Then
Set pFeatLyr = pMap.Layer(i)
Exit For
End If
Next i
' --------------------------------------------------
' symbol setup
Dim pColor As IRgbColor
Set pColor = New RgbColor
' use red. it's a good color
pColor.RGB = vbRed
Dim pSym As ISymbol
' based on feature type, make proper symbol, then assign to pSym
Select Case pFeatLyr.featureClass.ShapeType
Case esriGeometryPoint ' set up a marker symbol
Dim pMarkerSym As ISimpleMarkerSymbol
Set pMarkerSym = New SimpleMarkerSymbol
With pMarkerSym
.size = 4
.Color = pColor
'.Style = esriSMSX
End With
Set pSym = pMarkerSym
Case esriGeometryPolyline ' set up a line symbol
Dim pLineSymbol As ISimpleLineSymbol
Set pLineSymbol = New SimpleLineSymbol
With pLineSymbol
.Width = 1
.Color = pColor
'.Style = esriSLSDashDotDot
End With
Set pSym = pLineSymbol
Case esriGeometryPolygon ' setup a fill symbol
Dim pFillSymbol As ISimpleFillSymbol
Set pFillSymbol = New SimpleFillSymbol
With pFillSymbol
.Color = pColor
'.Style = esriSFSBackwardDiagonal
End With
Set pSym = pFillSymbol
Case Else
MsgBox "Invalid feature type"
GoTo EndProc
End Select
' create a new CustomSimpleRend
Dim pRend As IFeatureRenderer
Set pRend = New CustomSimpleRenderer.CustomSimpleRend
' set symbol. we must use ISimpleRenderer interface
Dim pSimpleRend As ISimpleRenderer
Set pSimpleRend = pRend
Set pSimpleRend.Symbol = pSym
Dim pGeoFL As IGeoFeatureLayer
Set pGeoFL = pFeatLyr
' finally, set the new renderer to the layer and refresh the map
Set pGeoFL.Renderer = pRend
pDoc.ActiveView.Refresh
pDoc.UpdateContents
GoTo EndProc
ErrHand:
'MsgBox "TestRenderer " & Err.Description
EndProc:
' set all variables to nothing
Set pApp = Nothing
Set pDoc = Nothing
Set pMap = Nothing
Set pFeatLyr = Nothing
Set pColor = Nothing
Set pSym = Nothing
Set pMarkerSym = Nothing
Set pLineSymbol = Nothing
Set pFillSymbol = Nothing
Set pRend = Nothing
Set pSimpleRend = Nothing
Set pGeoFL = Nothing
Exit Sub