IIF Function in Access query that adds three fields together and compares answer to another field

696 Views Asked by At

I'm using Windows Access 2010. I'm trying to run an IIF Function, using Expression Builder, in a query on one table that asks the query to add three fields together and compare the answer to a fourth field. If the sum of the three fields are equal to the fourth field return "Ok" if not equal return"Err".

This is the the expression I'm using:

SalmonRelSum: IIf([SalmonRelUM]+[SalmonRelAd]+
                  [SalmonRelUK]=SalmonReleasedCount],"Ok","Err")

When I run the query I get Err on all lines whether it is correct or not.

What am I doing wrong?

1

There are 1 best solutions below

0
On

Assuming that you really mean this:

IIf([SalmonRelUM]+[SalmonRelAd]+[SalmonRelUK]=[SalmonReleasedCount],"Ok","Err")
--------------------------------^

The problem is probably NULL values. You can use the NZ() function to treat them as zeroes:

IIf(NZ([SalmonRelUM], 0) + NZ([SalmonRelAd], 0) + NZ([SalmonRelUK], 0) =[SalmonReleasedCount], 
    "Ok", "Err"
   )