"I tried putting this field in the query....but it is a nested if statement (at least three if's)....the query didn't like having such a complicated calculation."
Function foo(TheID, TheClass_1ID) As Long
' here is your original statement
'=IIf([id]=1002,1,IIf([id]=1003,3,IIf([id]=1008,3,IIf([class_1id]="gnelson",
1,IIf([class_1id]="jharring",2,IIf([class_1id]="rbrown",3,4))))))
' replacing the field names with parameters
'=IIf(TheID=1002,1,IIf(TheID=1003,2,IIf(TheID=1008,3,IIf(TheClass_1ID="gnels
on",1,IIf(TheClass_1ID="jharring",2,IIf(TheClass_1ID="rbrown",3,4))))))
' broken into the separate parts
'=IIf(TheID=1002,1,
' IIf(TheID=1003,2,
' IIf(TheID=1008,3,
' IIf(TheClass_1ID="gnelson",1,
' IIf(TheClass_1ID="jharring",2
' ,IIf(TheClass_1ID="rbrown",3,
' 4))))))
If IsNull(TheID) Or IsNull(TheClass_1ID) Then
' if either is missing, exit with foo = 0
' or of course you could set your own default
Exit Function
End If
' replace the parts with a simple if-then
If TheID = 1002 Then
foo = 1
ElseIf TheID = 1003 Then
foo = 2
ElseIf TheID = 1008 Then
foo = 3
ElseIf TheClass_1ID = "gnelson" Then
foo = 1
ElseIf TheClass_1ID = "jharring" Then
foo = 2
ElseIf TheClass_1ID = "rbrown" Then
foo = 3
Else
foo = 4
End If
End Function