Division by Zero Error

C

clk

I am trying to make a summary query to show the percent of change in
test scores. I have it working except when a zero is entered.

In my query I have the following two fields:

PercentMoney: IIf([LegalCorrect]=0,0,[LegalCorrect]/[Legal])

PctGain: IIf(IsNull([PrevDate]) Or NZ([PercentMoney]=0),0,
(([PercentMoney]/
NZ(DLookUp("PercentMoney","qryDanielMemorialScoresLegalSummary","DMDate=
#" & [PrevDate] & "#"),0)))-1)*100

I thought I was handling the division by zero errors but it is still
throwing that error message.

Any help would be greatly appreciated.

Thank you.
 
R

Rob Parker

To use an IIf function to prevent a division by zero error, you need to test
the term which is the divisor, not the dividend. So, for example, your
first expression needs to be something like:

PercentMoney: IIf([Legal]=0,0,[LegalCorrect]/[Legal])

or maybe, depending on exactly what you're trying to achieve:
PercentMoney: IIf([Legal]=0,[LegalCorrect],[LegalCorrect]/[Legal])
or maybe something else - I don't understand exactly what you're trying to
accomplish here.

HTH,

Rob

BTW: the term NZ([PercentMoney]=0) in your expression for PctGain seems
strange; it will return 0 for every value of PercentMoney except Null, and
will return Null if PercentMoney is Null. Perhaps you want
nz([PercentMoney],0), which will return the actual value of PercentMoney
except when it is null, in which case it will return 0.
 

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

Division by zero 4
"Division by Zero" Question 2
Division By Zero error 2
"Division by zero", but... 2
Division by Zero Error 4
division by Zero and expression to complex 2
division by zero 5
Division by Zero 1

Top