ISelectionSet2 automation Error?

770
3
04-14-2011 11:59 AM
MattFancher
New Contributor III
The following code produces an error:

Public Sub Failure()

    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pMxDoc.FocusMap.Layer(0)
   
    MsgBox pFeatureLayer.Name 'displays correct layer name
   
    Dim pFeatureSelection As IFeatureSelection
    Set pFeatureSelection = pFeatureLayer
    Dim pSelectionSet As ISelectionSet2
    Set pSelectionSet = pFeatureSelection.SelectionSet
   
    MsgBox pSelectionSet.Count 'displays correct count
   
    Dim pFeatureCursor As IFeatureCursor
    pSelectionSet.Update Nothing, True, pFeatureCursor 'this line produces an automation error
    Dim pFeature As IFeature
    Set pFeature = pFeatureCursor.NextFeature
   
    MsgBox pFeature.Value(2)
   
End Sub

The exact error message is:

Run-time error '-2147467259 (800040005)':

Automation error
Unspecified error

Any advice on what I'm doing wrong?  I'm working in ArcGIS 9.3.1.
0 Kudos
3 Replies
DuncanHornby
MVP Notable Contributor
Try setting this line:

pSelectionSet.Update Nothing, True, pFeatureCursor 


to:

pSelectionSet.Update Nothing, False, pFeatureCursor 


Also help file says:

All edits to features that participate in a Topology or Geometric Network must be bracketed within an edit operation.
0 Kudos
MattFancher
New Contributor III
Duncan,

Thank you for the reply.  Unfortunately, I still get the error after making the substitution you suggested.  Also, no features in the map participate in a topology or a geometric network.

Matt
0 Kudos
DuncanHornby
MVP Notable Contributor
Matt,

What is the format of your data? I tried your code on some random shapefile I have and it worked. Your data isn't some sort of compressed (hence read only) dataset?

Duncan
0 Kudos