How to prevent divide by zero error

P

Paul B.

This is the control source for a textbox:

=Sum([AEDDLFiled])/([Total]-[AEDDLNotRequired])

If the query returns a zero value, then I get #Name in the textbox.

I would appreciate any help with the problem.

Cheers
 
A

Allen Browne

Add zero if Total equals AEDDLNotRequired, since that would give the zero
divisor.

Otherwise add the expression. Use IIf().

So:
=Sum(IIf([Total]=[AEDDLNotRequired], 0,
[AEDDLFiled] / ([Total]-[AEDDLNotRequired])))
 
P

Paul B.

Thanks Allen!

Your work here is very appreciated by all!

Allen Browne said:
Add zero if Total equals AEDDLNotRequired, since that would give the zero
divisor.

Otherwise add the expression. Use IIf().

So:
=Sum(IIf([Total]=[AEDDLNotRequired], 0,
[AEDDLFiled] / ([Total]-[AEDDLNotRequired])))

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Paul B. said:
This is the control source for a textbox:

=Sum([AEDDLFiled])/([Total]-[AEDDLNotRequired])

If the query returns a zero value, then I get #Name in the textbox.

I would appreciate any help with the problem.

Cheers
 
S

Stefan Hoffmann

hi Allen,

Allen said:
Add zero if Total equals AEDDLNotRequired, since that would give the zero
divisor.

Otherwise add the expression. Use IIf().

So:
=Sum(IIf([Total]=[AEDDLNotRequired], 0,
[AEDDLFiled] / ([Total]-[AEDDLNotRequired])))
I would prefer

IIf(([Total]-[AEDDLNotRequired])=0,...

I think it is better to test the divisor, than a mathematical equivalent
expression, which may be not the same due to rounding errors.


mfG
--> stefan <--
 
Top