Division By Zero error

T

Tray

I have a query with a field "payroll" and another "contribution". I also have
a calculated field to work out what percentage of the payroll was paid as a
contribution:

ratePaid: ([contribution]/[payroll])*100

This query works fine like this. But I want to be able to view those rows
with a ratePaid figure over a certain amount. I tried to put a simple
equation into the criteria field for ratePaid but get a Division By Zero
error. Any ideas of what i'm doing wrong??
thanks
 
A

Allen Browne

Use IIf() to identify the case where the divisor is zero:

ratePaid: IIf([payroll] = 0, Null, 100 * [contribution] / [payroll])
 
J

John Spencer

If payroll is ever zero then you will get that error.

Try the following expression.

RatePaid: IIF(Payroll=0,Null,(Contribution/Payroll)*100)

If you want zero returned if Payroll is zero, then replace null with zero.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 

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

Similar Threads


Top