Calculating field values to NULL results in 'Error running VBA code : User interrupt'


When the Field Calculator is used to calculate a field value to NULL using the equation [Field name] = is null, the following error displays:

"Error running VBA code : User interrupt."


It is not possible to calculate a field value to NULL using the Field Calculator. The calculation must be done using VBA and ArcObjects.

Solution or Workaround

Instructions provide an ArcObjects code sample that calculates a field to NULL. Null values are supported for all geodatabase fields, as well as for date fields in coverages and shapefiles.

This code does not edit a selection set. It edits the whole table and the edits cannot be undone.

  1. Start ArcMap.
  2. Open the Visual Basic Editor.

    In ArcMap, select Tools > Macros > Visual Basic Editor.

  3. In the Project Explorer window, expand Project and select ArcMap Objects > ThisDocument. Right-click on ThisDocument and select View Code.
    [O-Image] Visual Basic Project  Explorer
    Code in the project's ThisDocument code module only runs in the current map document. To store the code in all map documents, open the Normal.mxt ThisDocument code module instead.

  4. Paste the following code into the code module. Substitute "FieldName" with the name of the desired field in quotes.
    Option Explicit

    Public Sub SetNull()

    Dim pDispTab As IDisplayTable
    Dim pMXD As IMxDocument
    Dim pTable As ITable
    Dim pCursor As ICursor
    Dim pRow As IRow

    Set pMXD = ThisDocument
    Set pDispTab = pMXD.SelectedItem
    Set pTable = pDispTab.DisplayTable
    Set pCursor = pTable.Search(Nothing, False)
    Set pRow = pCursor.NextRow
    Do While Not pRow Is Nothing
    'enter the name of the field below
    pRow.Value(pTable.Fields.FindField("FieldName")) = Null
    Set pRow = pCursor.NextRow

    End Sub

  5. Close the Visual Basic Editor.
  6. Start an edit session in the Editor toolbar by selecting Editor > Start editing.
  7. Run the code.

    A. Click Tools > Macros > Macros to display the Macros dialog box.
    B. Select a macro and click Run.

Article ID:000006393

  • 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