Rob said:
I am trying to write a query that will look at 10 different items and
generate a result.
(If field 1 = 1 and Field 2 =1 and field 3 = "ok" and field 4 =3 etc. then
"Approved" else "Not Approved")
What Syntax is required to perform this calculation?
Look in help for the IIf() and Switch() functions. They are the closest,
but you will need to nest them and it could get pretty ugly. You might be
better off writing a custom function so the complexities are handled in a
code window rather than the expression in the query. For instance, what
you supplied so far would look like...
Approval: IIf(field1 = 1, IIf(field2 = 1, IIf(field3 = "ok", IIf(field4 =
3, "Approved","Not Approved"),
"Not Approved"), "Not Approved"), "Not Approved")
The same thing handled with a custom function would just be...
Approval: CustFunc(field1, field2, field3, field4)
In a module the code for CustFunc() can be as complicated as required but
still easy to follow because you have the ability to spread it over
multiple lines and add comments etc..
Function CustFunc(fld1 as integer, fld2 as integer, fld3 as String, fld4 as
integer) as String
If fld1 = 1 _
And fld2 = 1 _
And fld3 = "ok" _
And fld4 = 3 Then
CustFunc = "Approved"
Else
CustFunc = "Not Approved"
End if
End Function