View Full Version : Divide by Zero ERROR - HELP!!!
rkrause 07-20-2009, 12:04 PM I have a report Where my detail row is already summed up from my query. So example on of my fields is called SumOfGeneral_Repair.
Ok so in my report footer i have all my detail rows summed up again. I also have a textbox that is counting the rows that do not have a zero. So what i have in my report footer for formula is:
=Sum([SumOfGeneral_Repair])/[text39]
How would i incorparate that formula so i can forget the divide by zero error?
pbaldy 07-20-2009, 12:09 PM You can test in an IIf() and only do the division if it's greater than zero.
rkrause 07-20-2009, 12:25 PM OK So how would i do that in my formula that i posted?
MSAccessRookie 07-20-2009, 12:58 PM OK So how would i do that in my formula that i posted?
The Syntax of IIf() is
IIf({Condition to Test}, {Value if Test is True}, {Value if Test is False})
Kryst51 07-20-2009, 01:01 PM Iif([text39]>0,Sum([SumOfGeneral_Repair])/[text39] ,Sum([SumOfGeneral_Repair])
Disclaimer: I am not sure if this is correct.
MSAccessRookie 07-20-2009, 01:05 PM Iif([text39]>0,Sum([SumOfGeneral_Repair])/[text39] ,Sum([SumOfGeneral_Repair])
Disclaimer: I am not sure if this is correct.
I think you might want to treat the Null or 0 divisor as having a 0 returned value.
Note: the extra set of parenthesis are for clarification only and can be removed if you desire. I like to use them in formulas like this.
IIf([text39]>0, (Sum([SumOfGeneral_Repair])/[text39]) ,0)
Kryst51 07-20-2009, 01:06 PM I thionk you might want to treat the Null or 0 divisor as having a 0 returned value.
LOL, I have never been good at math..... :)
MSAccessRookie 07-20-2009, 01:09 PM LOL, I have never been good at math..... :)
Did that formula work for you?
Kryst51 07-20-2009, 01:12 PM Did that formula work for you?
Not sure if you were asking me but I didn't test it. My thinking and reasoning skills are a little off today, due to the fact that I am tired..... So my reasoning was wrong when I worked it out in my head.
MSAccessRookie 07-20-2009, 01:15 PM Not sure if you were asking me but I didn't test it. My thinking and reasoning skills are a little off today, due to the fact that I am tired..... So my reasoning was wrong when I worked it out in my head.
Once you have worked things out, let us know if you have any more questions.
boblarson 07-20-2009, 01:21 PM I wouldn't use
IIf([text39]>0,
I would use
IIf([text39]<>0,
Because what if you have a negative number? It would get bypassed.
tebule 07-20-2009, 01:43 PM Use the Nz function. =nz(me.text39/5, 0) if the me.text = 0 then a null value would be the result. with the nz function it will return a 0 in the code I have included.
boblarson 07-20-2009, 01:51 PM Use the Nz function. =nz(me.text39/5, 0) if the me.text = 0 then a null value would be the result. with the nz function it will return a 0 in the code I have included.
This will not work. If you have /5 then it will but the problem is if the field is a zero that you are dividing BY.
tebule 07-20-2009, 02:06 PM I beg your pardon, boblarson is correct.
rkrause 07-21-2009, 03:38 AM KRYST51, worked good. thanks.
|