PROBLEM
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.
Warning:
This code does not edit a selection set. It edits the whole table and the edits cannot be undone.
Note:
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.
Code:
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
pRow.Store
Set pRow = pCursor.NextRow
Loop
End Sub
Article ID:000006393
Get help from ArcGIS experts
Download the Esri Support App