How to prevent divide by zero error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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])))
 
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
 
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 <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top