jennhird

Getting "Unexpected Error" message with IFeatureClass.DeleteField method

Discussion created by jennhird on Aug 31, 2010
Latest reply on Sep 2, 2010 by jennhird
Hello,

I am writing a program (in VB, ArcGIS 9.2 - yes, I'm a bit behind the times), that takes a set of three feature classes from a file geodatabase (one point, one line, and one polygon), selects a series of features from each class, and exports the selected features to a new file geodatabase.  That part works fine. 

In part of the code, I add a new field to the original feature classes to hold temporary information on which features have been selected.  However, after I export the selected features I want to delete this temporary field from each of the original feature classes, as well as the new ones (the field transfers with the rest of the fields right now).  This seems simple enough, but I keep running into an error on the "pFClass.DeleteField pField" line.  The error is: "Run-Tim Error '-214729887(800040651)' Unexpected Error".

In case it is relevant, here is the piece of code  in which I add the new field (within a subroutine that selects the point features, for example):

'---------------------------------------------------

    'Create field "QC_Sel" if it does not exist

    Dim intPosQCSelField As Integer
    intPosQCSelField = pPtFClass.FindField("QC_Sel")

    If intPosQCSelField = -1 Then
   
        Dim pNewQCField As IField
        Set pNewQCField = New Field
       
        Dim pNQCFieldEdit As IFieldEdit
        Set pNQCFieldEdit = pNewQCField

        With pNQCFieldEdit
            .Name = "QC_Sel"
            .Type = esriFieldTypeString
            .DefaultValue = ""
            .Editable = True
            .Length = 20
        End With
       
        pPtFClass.AddField pNewQCField
   
    End If

'---------------------------------------------------

And here is the code where I set the value of the new field for the selected features (from within the same subroutine as above):

'---------------------------------------------------

'Fill field "QC_Sel" for those features in the pPtSelSet seletion set
'(within an edit session)

    Dim pEditWorkspace As IWorkspaceEdit
    Set pEditWorkspace = pFGDBWorkspace

    pEditWorkspace.StartEditing True 'allows undo

    Dim pPtFeatCursor As IFeatureCursor
    pPtSelSet.Search Nothing, False, pPtFeatCursor

    Dim pPtFeat As IFeature
    Set pPtFeat = pPtFeatCursor.NextFeature
   
    Do While Not pPtFeat Is Nothing
        pPtFeat.Value(intPosQCSelField) = "Selected"
        pPtFeat.Store
        Set pPtFeat = pPtFeatCursor.NextFeature
    Loop
   
    pEditWorkspace.StopEditing True 'saves edits

'---------------------------------------------------


Now, here is the code of the subroutine I wrote for deleting the new field (it is called for each feature class I want to remove the field from):

'---------------------------------------------------

    Private Sub deleteField(pFClass As IFeatureClass, strFieldName As String)

        Dim pFields As IFields
        Set pFields = pFClass.Fields

        Dim lngPosField As Long
        lngPosField = pFields.FindField(strFieldName)

        If lngPosField <> -1 Then

            Dim pField As IField

            Set pField = pFields.Field(lngPosField)

            pFClass.deleteField pField '** Get Error '-214729887(800040651)' "Unexpected error"
   
        End If

    End Sub

'---------------------------------------------------

There were a few times that this ran OK, but not on every different data set I tried.  Now it is giving the error every time (and I haven't changed anything).  I have tried running this on a fresh data set (i.e. one that I had not been using for testing throughout my coding), and it still doesn't work.  So I don't think it is a matter of corrupt file geodatabases.  If anyone has run into this error before, or has any suggestions or ideas regarding where the error might be coming from, that would be very, very much appreciated!!

Thank you,
Jen Hird

Outcomes