IFeatureClass:FeatureCount & ITable::RowCount return incorrect record count

Last Published: April 25, 2020


IFeatureClass:FeatureCount and ITable::RowCount return incorrect record counts after deleting a record using IFeature::Delete. This behavior only occurs with shapefiles.


This problem occurs due to a known limit in the software.


Set IFeatureCursor equal to nothing before calling the FeatureCount or RowCount methods to return the correct row counts.
  1. Start ArcMap.
  2. Create a new UIButtonControl.

    For more information on creating a UIControl, see the ArcGIS Desktop Help topic 'How to create custom commands with VBA.'

  3. Right-click the UIButtonControl and select View Source.
  4. Copy this code into the UIButtonControl's click event.

    Dim StrPathToDataBase As String
    StrPathToDataBase = "H:\esri_data\world_data\usa"

    ''This is the name of the ShapeFile...
    Dim StrFeatureClassName As String
    StrFeatureClassName = "States"
    ''This is the connection information that is used to access the WorkSpace...
    Dim ppropset As IPropertySet2
    Set ppropset = New PropertySet
    ppropset.SetProperty "DATABASE", StrPathToDataBase

    Dim pWorkSpaceName2 As IWorkspaceName2
    Set pWorkSpaceName2 = New WorkspaceName

    pWorkSpaceName2.WorkspaceFactoryProgID = "esriCore.ShapeFileWorkspaceFactory"
    pWorkSpaceName2.ConnectionProperties = ppropset

    Dim pname As IName
    Set pname = pWorkSpaceName2

    Dim pFeatureWorkspace As IFeatureWorkspace
    Set pFeatureWorkspace = pname.Open

    Dim pfeatureclass As IFeatureClass
    Set pfeatureclass = pFeatureWorkspace.OpenFeatureClass(StrFeatureClassName)

    Debug.Print pfeatureclass.FeatureCount(Nothing) & " FeatureCount - AD - ..."

    Dim pfeatcursor As IFeatureCursor
    Set pfeatcursor = pfeatureclass.Search(Nothing, True)

    Dim pfeat As IFeature
    Set pfeat = pfeatcursor.NextFeature
    If pfeat Is Nothing Then
    MsgBox "Nothing"
    End If
    Debug.Print pfeat.Value(0)


    Dim ptable As ITable
    Set ptable = pfeatureclass
    Debug.Print pfeatureclass.FeatureCount(Nothing) & " FeatureCount - AD - ..."
    Debug.Print ptable.RowCount(Nothing) & " From Table..."

    ''If this isn't set to NOTHING the count is off...
    Set pfeatcursor = Nothing

    ''These are now correct if you set pfeatcursor = NOTHING....
    Debug.Print pfeatureclass.FeatureCount(Nothing) & " FeatureCount - AD - ..."
    Debug.Print ptable.RowCount(Nothing)

    This code will delete a record in the test feature class

  5. Change the StrPathToDataBase variable to point to a directory that contains a shapefile and set the StrFeatureClassName to the name of a shapefile in that directory.

Article ID:000005930

  • ArcMap 8 x
  • ArcMap 9 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic