Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Variables in the report doesn't seem to work! 1

Status
Not open for further replies.

Maim

Programmer
Jun 25, 1999
106
CA
I have a report that prints totals of costs for clients and their projects. So I have 2 group fields. In the Details section, I have the field Cost.AMT and am summing this for every project. The Client has a condition, if the amt is larger than 1000 add it to total.

I created another formula and placed it next to the Sum of Amount field for projects. This formula contains the following:
Code:
NumberVar Tot;
If Sum({Cost.Amt},{Client.Name}) >= 1000 then
    Tot := Tot + Sum({Cost.Amt},{Client.Name})
else
    Tot := Tot

Now in the Client section I put a formula that should display the total in the variable I am using
Code:
NumberVar Tot;
Tot

But this only displays a zero. I've also tried declaring the variable as Global NumberVar Tot, but that desn't change my result.

While in the Projects Group, the variable is incremented when I preview as I have a last entry of something like 29,204.95 and this is what should display at the Client level. What am I doing wrong?

I think I'll go try a running total, but I am still interested in your thoughts...

Vic
 
Could be to do with the order in which your formulae are being evaluated, could be that your 'second' formula is actually being evaulated before your 'first' formula.
 
Well, this is how I have my report set up...

========================================
Client - Header -> Client Name + any other info

Project - Header -> Project Name, first formula to get Amt, then conditional formula to add number to variable Tot

Details -> Hidden

Project - Footer -> Hidden

Client - Footer -> Formula to display my variable Tot only...
========================================

What I figure is it goes from Client Header -> Project Header -> Details -> Project Footer ->Client Footer...

I tried a Running Total formula, but that doesn't work either, can't use conditional formulas to obtain a sum :(
 
Try declaring your variable as 'shared'.
 
AAP, you are a genius :)

Dunno why I didn't try that one... oh well, now I know for next time.

Thanks again...
 
FYI.
Declaring a variable as shared means it can be shared between subreports and the main report. So why does this fix the problem when there is no subreport?
A side effect of declaring a variable as shared is forcing the evaluation time of the formula to be "WhenPrintingRecords", as shared variables can only be evaluated at this time.
You should be able to achieve the same result with global variables with

WhilePrintingRecords ;
NumberVar Tot

Your other formula is evaluated while printing automatically because it contains an aggregate function.
 
I'm using a subreport for other info, but it isn't related to the number I'm trying to retreive, that's why I didn't even try Shared variable, but it looks like it's needed if there's a subreport present (bug?).
 
Oops, misunderstood... Never mind :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top