views:

51

answers:

1

I have the following expression in an MS Access Query, where some of these values can be null and despite the cast to a Decimal and the Not Zero (NZ) function, I still get an overflow error.

I hope someone can help me find the bug?

Sum(Cdec(Nz([TotalPrice]/([tbl_ArticlesPerOrder]![Amount]*[Total])*[tbl_ArtikelRemoveFromSawList]![Amount]),0))

EDIT: Removing the TotalPrice division removes the overflow. So I suspect a division by 0. Any way to deal with that?

+2  A: 

I would try to see if you can build an IFf statement within your sum to handle the division by zero.

e.g.

IIf([tbl_ArticlesPerOrder]![Amount]*[Total])=0,0,[TotalPrice]/([tbl_ArticlesPerOrder]![Amount]*[Total])

MS LINK: Avoiding divide by zero errors in Access

(Edited based on Kev's comments)

kevchadders
I did exactly that and then got the overflow error again. Now I'm doing this calculation through VBA and I get a type mismatch error. Any ideas?
Tony
The above function was checkin the wrong part of the fraction, you need to check if ([tbl_ArticlesPerOrder]![Amount]*[Total]) is 0 not[TotalPrice]. Does it still error if you do that?
Kevin Ross
sorry yes, well spotted Kev.
kevchadders
No problem, if I had a pound/dollar for every time I made a mistake like that...........
Kevin Ross