a00578107

Updating code from coverages to SDE - Object variable or with block variable not set

Discussion created by a00578107 on May 10, 2010
Hello,

I have an old mxd file that code has been written behind to automatically create a series of pdf maps (at the click of a button). In the past the code has accessed and loaded coverages, but we now have our data stored in a SQL Server SDE Geodatabase. I am trying to update this file, and I don't seem to have done it correctly, as I am getting the error caught in the renderer code. Here is what I have (the line that throws the error is near the bottom):

Public Sub addSDE_FeatureClass(featureClassName As String)

Dim pFLayer As IFeatureLayer
Set pFLayer = New FeatureLayer

'Call the workspace factory and create the workspace
Dim pAWFactory As IWorkspaceFactory
Set pAWFactory = New SdeWorkspaceFactory

'Create the property set which whill send all the needed variables to connect to the sde database
Dim pPropset As IPropertySet
Set pPropset = New PropertySet


With pPropset
.SetProperty "Server", "direct_connect"
.SetProperty "Instance", "sde:sqlserver:*****"
.SetProperty "Database", "*****"
.SetProperty "user", "*****"
.SetProperty "password", "*****"
.SetProperty "version", "sde.DEFAULT"
End With

'Bring the variables set above into the dialog box to make the connection
Dim pFWorkspace As IFeatureWorkspace
Set pFWorkspace = pAWFactory.Open(pPropset, 0)

'Get the Sanline feature class from the sde database
Dim pFClass As IFeatureClass
Set pFClass = pFWorkspace.OpenFeatureClass(featureClassName) 'SS_Sanline ID_ADOPT_A_ROAD

Set pFLayer.FeatureClass = pFClass

'Name the layer in the TOC
'Dim pLayer As ILayer
'Set pLayer = pFLayer
'pLayer.Name = "sanline"

'Declare and set the imxdocument variable
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

'Get the active map and add the layer to it
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap

pMap.AddLayer pFLayer
pFLayer.Visible = False

End Sub

'Add the index2500 featureclass to the map and render it.
Call addSDE_FeatureClass("CHWKSDE.DBO.BM_Index2500")
Call renderIndex2500_mainMap(mainMap)

Private Sub renderIndex2500_mainMap(theMap As IMap)

Dim theColor As IRgbColor
Dim theOutline As ISimpleLineSymbol
Dim theSymbol As ISimpleFillSymbol
Dim theRenderer As ISimpleRenderer
Dim i As Integer
Dim theLayer As ILayer
Dim theFeatureLayer As IFeatureLayer
Dim theGFLayer As IGeoFeatureLayer


'Set the outline style.
Set theColor = New RgbColor
theColor.RGB = RGB(168, 35, 135)
Set theOutline = New SimpleLineSymbol
theOutline.Style = esriSLSSolid
theOutline.Width = 2
theOutline.Color = theColor

'Set the symbology for the featurelayer.
Set theSymbol = New SimpleFillSymbol
theSymbol.Outline = theOutline
theSymbol.Style = esriSFSNull

'Set the symbology to the simple renderer.
Set theRenderer = New SimpleRenderer
Set theRenderer.Symbol = theSymbol

'Get the index2500 layer
For i = 0 To theMap.LayerCount - 1
If theMap.Layer(i).Name = "CHWKSDE.DBO.BM_Index2500" Then
Set theLayer = theMap.Layer(i)
End If
Next
Set theFeatureLayer = theLayer
Set theGFLayer = theFeatureLayer

'Set the renderer to the featurelayer.
Set theGFLayer.Renderer = theRenderer 'this throws the error


Set theColor = Nothing
Set theOutline = Nothing
Set theSymbol = Nothing
Set theRenderer = Nothing
Set theLayer = Nothing
Set theFeatureLayer = Nothing
Set theGFLayer = Nothing

End Sub

The actual error thrown is: Run-time error '91': Object variable or Wish block variable not set. I have been staring at this for ages now and am really stuck. Any help would be HUGELY appreciated.

Thanks!

Outcomes