How to use a symbology renderer with a .lyr file in VBA?

Discussion created by mduvall3 on Aug 8, 2012
Latest reply on Aug 8, 2012 by Neil
I am trying to get this to work from a single custom button on a custom toolbar.

At the line near the bottom: [Set GetRenderer = pGFLayer.Renderer]

I get the following error: [Run-time error '91': Object variable or With block variable not set]

Any suggestions? What still needs to be ???set????


Private Sub UIButtonControl_Symbolize_Click()

Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Dim sName As String
sName = "Wetlands"
Dim pLayer As ILayer
Dim l As Long
For l = 0 To pMap.LayerCount - 1
  If pMap.Layer(l).Name = sName Then
    Set pLayer = pMap.Layer(l)
    Exit For
  End If
Next l
If pLayer Is Nothing Then Exit Sub

    Dim pGFLayer As IGeoFeatureLayer
    Dim pGFLayer2 As IGeoFeatureLayer
    Dim pGFLayer3 As IGeoFeatureLayer
    Dim pGFLayer4 As IGeoFeatureLayer
    Set pGFLayer3 = pMxDoc.FocusMap.Layer(0)
    If pGFLayer3.Name = "Inventory_Points" Then
    Set pGFLayer3.Renderer = GetRenderer("C:\geodata\wetlands\GISWetlandToolSupport\Inventory_Points.lyr")
    End If
    Set pGFLayer2 = pMxDoc.FocusMap.Layer(1)
    If pGFLayer2.Name = "Support_Points" Then
    Set pGFLayer2.Renderer = GetRenderer("C:\geodata\wetlands\GISWetlandToolSupport\Support_Points.lyr")
    End If
    Set pGFLayer = pMxDoc.FocusMap.Layer(2)
    If pGFLayer.Name = "Support_Lines" Then
   Set pGFLayer.Renderer = GetRenderer("C:\geodata\wetlands\GISWetlandToolSupport\Support_Lines.lyr")
    End If
    Set pGFLayer4 = pMxDoc.FocusMap.Layer(3)
    If pGFLayer4.Name = "Wetlands" Then
    Set pGFLayer4.Renderer = GetRenderer("C:\geodata\wetlands\GISWetlandToolSupport\Wetlands.lyr")
    End If
End Sub


Function GetRenderer(sFile As String) As IFeatureRenderer
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pGxFile As IGxFile
    Set pGxFile = New GxLayer
    pGxFile.Path = sFile

    Dim pGxLayer As IGxLayer
    Set pGxLayer = pGxFile
    Dim pGFLayer As IGeoFeatureLayer
    Set pGFLayer = pGxLayer.Layer
    Set GetRenderer = pGFLayer.Renderer

End Function