Crystal Reports Tip #2: Formulas in Group Headers…
Lies, Damn Lies, and Benchmarks…
Crystal Reports Tip #1: Running totals in formulas…
Crystal Reports. Love it or hate it, at some point, as a developer, you *will* use it. And it’s got more gotchas than a George W. Bush proposal. I’m going to add all the one’s that *I* run across in my blog, just so that I don’t forget what they are!
Here’s the first one that bit me *REALLY* hard this week.
I was working on a report that has subreports with columns that were totaled and the total sent back to the main report. Easy, right? Well, for some reason, I was getting a zero (0) back when I was expecting a number. Examining the running total in the subreport indicated that the number was being calculated, it just was not being sent to the main report. Grrrr…. After a LOT of digging, I discovered something… I was using one formula to send four subreport running totals to the main report. Some of the subreport variables WERE making it to the main report… WTF!?! It turns out that one of the subreport running totals had a null value in it for certain subreports. When doing an assign of the variable to be passed up the the main report, the code would assign the running total to the variable. Unfortunately, if the running total had a NULL, the assignment line AND THE REST OF THE FORMULA WOULD FAIL WITH NO FIGGING ERROR MESSAGE THROWN! (Note: There were a lot of swear words said when this was discovered…)
Which leads us to Crystal Tip #1:
If a running total value is used in a formula, ALWAYS, ALWAYS, ALWAYS wrap it up in a null check. Here is the code:
if not IsNull({#SomeRunningTotalValue} then
DoWorkWithTheRunningTotal
else
DoSomeWorkWithoutTheRunningTotal
Maybe this will save someone else from losing a day or two…