Zero is a value you will get errors if txtCraftLabEst or txtFirewatchLabEst or
txtCraftSuprLabEst is equal to zero and you try to calculate a value based on
those fields when the value of the field is zero.
If txtEstimatedCost is equal to zero you will automatically get zero returned
as the result - unless the above is true for the denominator (=0) is involved.
You could use
Switch(IsNull([costcode]) Or IsNull(costtype), 0
, [costcode]="013210" And [costtype]="05320" AND txtCraftLabEst<>0,
[txtEstimatedCost]/[txtCraftLabEst]
, [costcode]="020110" and [costtype] ="05320" AND txtFirewatchLabEst<>0,
[txtEstimatedCost]/[txtFirewatchLabEst]
, [costcode]="064201" and [costtype]="05320" AND txtCraftSuprLabEst<>0,
[txtEstimatedCost]/[txtCraftSuprLabEst]
, True, Null)
John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
Alberta said:
OK I got this to work by putting () around [costcode] as well as [costtype].
Could I use the IsNull if the txtEstimatedCost is zero as well? Right now if
the txtEstimatedCost is zero, I get an error message #Num!, same if the
txtActualCost is zero.
:
Hi Laurie,
You could add another IIf() function:
IIf(IsNull([costcode] Or IsNull(costtype), 0, [your existing IIf() functions
here] )
Just a note that you can use the Switch() function to eliminate the need
to have all those nested IIf() functions.
=Switch(IsNull([costcode] Or IsNull(costtype), 0, [costcode]="013210" And
[costtype]="05320",
[txtEstimatedCost]/[txtCraftLabEst], [costcode]="020110" and [costtype]
="05320", [txtEstimatedCost]/[txtFirewatchLabEst], [costcode]="064201" and
[costtype]="05320", [txtEstimatedCost]/[txtCraftSuprLabEst], True, Null)
Look in your online help for details about the Switch() function.
Clifford Bass
Alberta Rose wrote:
Can anyone help me with this? I need to know where to put the coding to tell
the formula that if there is no value in any of the txt's, to return a value
of zero.
=IIf([costcode]="013210" And [costtype]="05320",
[txtEstimatedCost]/[txtCraftLabEst], IIf([costcode]="020110" and
[costtype]="05320",[txtEstimatedCost]/[txtFirewatchLabEst],
IIf([costcode]="064201" and [costtype]="05320",
[txtEstimatedCost]/[txtCraftSuprLabEst],Null)))
Thanks so much...Laurie
.