I'm trying to write an expression that circumvents a divide by zero error. Expr4 and 5 may or may be Null, Zero or an integer greater than 0. I want to evaluate Expr4 and 5 together in Expr2. I've been trying to work with some version of the following all day, but Access keeps defaulting to the original expression I had stored.
The original expression reads as follows:
Expr2:iif([datum1]+[datum2]+[datum3]+[datum4]=0,0,IIf([datum3] Is Null,[datum1]/[datum2],IIf([datum1] Is Null,[datum3]/[datum4],([datum3]+[datum1])/([datum4]+[datum2]))))
This one works, but I get an error if Datum 1 or 3 is Null and the other Datum equal 0. I tried fudging around with this expression to massage-out the error, and it just became impossible to manage. When I tried to do was create two new expression to manage datum 1 and 2 together and datum 3 and 4 together. I figured I could condense the work of those two expressions into a new Expr 2 as follows:
Expr2: iif(([Expr4] is null) AND ([Expr5] is null),Null,(iif(([Expr4] is null) AND ([Expr5] is not null),[Expr5],(iif(([Expr5] is null) AND ([Expr4] is not null),[Expr4],(iif(([Expr4]+[Expr5])=0,0,(([Expr4]+[Expr5]/2)))))
When I put this into the expression builder or copy the expression directly into the query design, Access reverts back to the original expression. There must be something wrong with it, and it's probably breathtakingly simple, but I don't see it. Would somebody mind seeing what I am clearly incapable of seeing?
Thanks,
-Rob