Intro: I have a very complex report. To make it a bit more easy, I build my report this way: In VS.net, I have a class. In the report I made a "Field Definitions Only"-file (ttx) which is exactly the same as the class. In code behind I set the class as the datasource of the (sub)report.
Problem: One class (and also the ttx-file) has the following fields: PriceTraditional, PriceCommercial. And there are 2 formulaFields which are SumPriceTraditional, SumPriceCommercial.
When the class is empty, the datasource is also empty. This is when the error occurs. Probably because I take a sum of a field that is NULL.
Solutions I tried (but don't work):
- I tried to change PriceTraditional with a formulaField (ex: PriceTraditionalDummy; with formula: if isnull({DamageForReport.PriceTraditional}) then 0 else {DamageForReport.PriceTraditional}. But then I get an error: A number is required here. (Which is caused by the else part of the structure.
- I tried turning on and off the default values replacing (no result)
Question: I just want to have a report where I can use that Sum-FormulaField without blowing up the report if the field used in the sum is empty.
Any advice on how to solve this would be great!!
Kind regards,
Wim
Just follow the steps described in this
post
http://crystalrepterrinfo.blogspot.com/2009/11/error-on-sum-in-formula-field-crystal.html
Some things that you can try are to either cast the 0 as Currency using CCur or cast {DamageForReport.PriceTraditional} to number using CDbl or ToNumber.
It seems that for some reason it thinks that the 0 in the first part and the {DamageForReport.PriceTraditional} in the second part are of different types so you can cast one to match the other.
I haven't tried either of these, but it may be as simple as using $0 or 0.0 instead of 0.
Just throwing out some ideas. Hope it helps.