I have a program written in Visual Basic through ArcGIS 9.3 which has worked fine for a few years and now suddenly I get an error every time I try to run it. I have not updated my programs in the recent past and the programming language seems sound to me. My other programs seem to work. Can anyone look at this and help me figure out what might be causing a problem. I get Run-Time error '91' Object variable or With Block variable not set. I have posted the code below, the code I have provided is supposed to go through each layer in my .mxd until it finds one with features selected in it. I get an error on the very last line If pSelSet.Count > 0 Then Exit Do and I can't figure it out.
Public Sub UpdateData()
'On Error GoTo EH:
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pActiveView As IActiveView
Dim pFeatureLayer As IFeatureLayer
Dim pEnumLayer As IEnumLayer
Dim pLayer As ILayer
Dim pFeature As IFeature
Set pMxDoc = Application.Document
Set pEnumLayer = pMxDoc.FocusMap.Layers
Set pLayer = pEnumLayer.Next
Dim pFeatureSelection As IFeatureSelection
Dim pSelSet As ISelectionSet
Dim pID As New UID
pID = "esriCore.Editor"
Dim pEditor As IEditor
Dim pWorkspace As IWorkspace
Dim pDataset As IDataset
Dim pEnumFeature As IEnumFeature
Dim Phasenum As Integer
'========================================================
Do Until pLayer Is Nothing
If TypeOf pLayer Is IFeatureLayer Then
Set pFeatureSelection = pLayer
Set pSelSet = pFeatureSelection.SelectionSet
If pSelSet.Count > 0 Then Exit Do
End If