[GIS] Type mismatch error in Calculate Field tool in ArcGIS 10.1

arcgis-10.1errorfield-calculator

I'm trying to run a rather lengthy model (built in ArcGIS 9.3.1) in ArcGIS 10.1 and I'm recieving an error on a Calculate Field tool. The error is – Type mismatch: 'iif'.

This error is refering to an expression in the tool: iif(IsNull( [PID] ) ,NA,[PID]).

enter image description here

I tried "if" instead of "iif" but then recieved a generic error.

I never had this issue when running the model in 9.3.1. I'm not sure what to do here. Any suggestions?

Best Answer

You can't use iif directly in field calculator expressions, you need to use the code block. There are some examples on the Field Calculator Examples help page.

Python:

Expression:
Reclass(!WELL_YIELD!)

Expression Type:
PYTHON_9.3

Code Block:
def Reclass(WellYield):
    if (WellYield >= 0 and WellYield <= 10):
        return 1
    elif (WellYield > 10 and WellYield <= 20):
        return 2
    elif (WellYield > 20 and WellYield <= 30):
        return 3
    elif (WellYield > 30):
        return 4

VBA:

Expression:
density

Expression Type:
VB

Code Block:
Dim density
If [POP90_SQMI] < 100 Then
density = "low"

elseif [POP90_SQMI] < 300 Then
density = "medium"

else
density = "high"
end if