Modify feature using VB code on a version

Discussion created by dan.nguyen27 on May 24, 2011
Latest reply on May 25, 2011 by jamesfreddyc
I wrote some VB code (attached at the end of this post) to change value of a field of a set of selected features.
It works fine when the features is from a local shape file.
When I run it against features from a version, it wipe out all the records in the feature attribute table.
It seems that the pFeature.Store is where that happens.

Does anyone have experience doing similar task and have been successful?

This code basically select all features that that resulted from the query filter, then set the field 'CLEditResponse' for the feature to 3.

Thanks in advance for any help at all.


Sub ChangeCLEditToAbsoluteSelect()

    Dim pLayer As IFeatureLayer
    Dim pFeatureClass As IFeatureClass
    Dim pFeatureCursor As IFeatureCursor
    Dim pFeature As IFeature
    Dim pEditTask As IEditTask
    Dim pEditor As IEditor
    Dim pEditSketch As IEditSketch
    Dim pDoc As IMxDocument
    Dim pMap As IMap
    Dim pApp As IApplication
    Dim pQF As IQueryFilter
    Dim pID As UID
    Dim gLayer As GroupLayer
    Dim LayerList As EnumGPName

    'Get the current map
    'Set pDoc = ThisDocument
    Set pApp = Application
    Set pDoc = pApp.Document
    Set pMap = pDoc.FocusMap
    Set pID = New UID
    pID.Value = "escriEditor.Editor"
    Set pEditor = Application.FindExtensionByCLSID(pID)
    Set pEditTask = GetEditTaskByName(pEditor, "Modify Feature")
    Set pEditor.CurrentTask = pEditTask
    Set pEditSketch = pEditor
    Dim STA_ID As String
    Dim enumFeature As IEnumFeature
    Dim feature As IFeature
    Dim i As Integer
    Dim Layers(0 To 1) As String
    Layers(0) = "Tap"
    Layers(1) = "Tee"
    Set enumFeature = pMap.FeatureSelection
    Set feature = enumFeature.Next
    STA_ID = feature.Value(feature.Fields.FindField("EVENTID"))
    Dim pFeatureSelect As IFeatureSelection
    Dim pSelectSet As ISelectionSet
    Dim pMainActiveView As IActiveView
    Set pMainActiveView = pMap
    Dim pFilter As IQueryFilter
    Set pFilter = New QueryFilter
    Dim strQuery As String
    strQuery = "STATIONSERIESEVENTID = '" & STA_ID & "'"
    Dim pSelectLayerDef As IFeatureLayerDefinition
    For i = LBound(Layers) To UBound(Layers)

        Set pLayer = FindLayerByName(pMap, Layers(i))
        Set pSelectLayerDef = pLayer
        Set pFeatureSelect = pLayer
        pFilter.WhereClause = strQuery
        pFeatureSelect.SelectFeatures _
        pFilter, esriSelectionResultNew, False
        Dim pSelectClass As IFeatureClass
        Set pSelectClass = pLayer.FeatureClass
        Dim pFCursor As IFeatureCursor
        Set pFCursor = pSelectClass.Search(pFilter, False)
        Set pFeature = pFCursor.NextFeature
        Do While Not pFeature Is Nothing
            pFeature.Value(pFeature.Fields.FindField("CLEDITResponse")) = 3
            Set pFeature = pFCursor.NextFeature
End Sub