Error Message
The following error occurs when using the Field Calculator:
"Error running VBA code: User Interrupt"
Cause
There is a syntax error in the VBA code.
Solution or Workaround
Warning:
The procedure below is for ArcGIS 9.3.1 or earlier versions. Starting at ArcGIS 10.0, expressions in the Calculator are created using only VBScript or a standard Python format.
Examine the code for the syntax error. To find the error, compile the code in the VBA editor provided with ArcMap.
- With the Field Calculator dialog box open, use the mouse to select the code. Right-click and select 'Copy.'
- Click 'Cancel' to close the Field Calculator dialog box.
- Select 'Tools > Macros' to create a new VBA macro.
- Type a name for the macro in the Macros dialog box; for example 'Test'. Make sure to create the macro in the document. Click 'Create.'
- There should now be an empty subroutine in the VBA editor that can be used to test the code's syntax. Right-click inside the subroutine and select 'Paste' to paste the code copied from the Field Calculator in Step 1. The code should look similar to this:
Code:
Sub test()
Dim x As String
x = ucased([NAME_FIELD])
End Sub
- Test the code in this environment. Change the field parameter to a hard-coded string.
Code:
Sub test()
Dim x As String
x = ucased("Ziggy Stardust")
End Sub
- Add a line of code to call up a message box with the output of the code for this test string.
Code:
Sub test()
Dim x As String
x = ucased("Ziggy Stardust")
MsgBox x
End Sub
- Select 'Tools > Macros' and click 'Run' to run the macro and check for proper syntax.
- If the macro has any syntax errors, a VBA error will be generated. In this example, the error is that the proper name for the uppercase function is not being used. The proper name for this function is 'UCase' and not 'ucased'.
- Modify the code to correct the syntax error. Run the macro again.
- Using copy/paste, return to ArcMap, open the Field Calculator, and correct the syntax there.
- Click OK on the Field Calculator dialog box to execute the calculation.