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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing values in reports with values in subreports

Status
Not open for further replies.

Flupke

Programmer
Jun 26, 2002
94
0
0
BE
I have a report with a value that is a sum in a group footer. In that report is a subreport with also a value that is a sum in a group footer.
How can I make a formula that compares these two values.
When I make a formula in the main report, I can of course access the value in the main report, but I do not seem able to access the value in the subreport in order to compare those two.
Can anyone help me?

Many thanks,

Michel
 
Set up the value in the subreport as a shared variable. If the subreport is linked to the main report on the group field, then your shared variable would look like:

whileprintingrecords;
shared numbervar subamt := sum({table.amt});

You must place this formula on the subreport,e.g., in the subreport footer.

Then in the main report, create a formula and place it in a section below the one in which the subreport executes,i.e., if the subreport is in GH_a, place the formula in an inserted GH_b section or in a GF section:

whileprintingrecords;
shared numbervar subamt;
if subamt > sum({maintable.amt},{maintable.groupfield}) then 1 else 0 //sample comparison

In the main report, you should also set up a reset formula in case the subreport has a null value, and this formula should be placed in a section before the one in which the subreport is executing or after the section in which the comparison formula is located:

whileprintingrecords;
shared numbervar subamt := 0;

-LB
 
Thank you very much for your kind help.
However, I did not manage to achieve my goal, because I'm not so familiar with programming in Crystal Reports.

Am I right in supposing that "subamt" is the name of the variable?
In the formula in the subreport, I get an error message "A number is required here". When I delete the colon between "subamt" and "=", then I can save the formula without errors

whileprintingrecords;
shared numbervar subamt=sum({tblTV_Stortingdetails.TVSD_Bedrag});

As a result in the subreport, I do not see a value, but only "False".

Now, how can I verify that the correct value is calculated?
When I put the code

whileprintingrecords;
shared numbervar subamt;
subamt - Sum ({tblTV_Inkomstendetails.TVID_Bedrag}, {tblTV_Sessies.TVSE_Begintijd}, "daily")

in my main report, the result makes me believe the value of the variable stays zero. So I think the value in the subreport is not correctly calculated or transmitted.
As a result in the main report, I only see the value of
-Sum ({tblTV_Inkomstendetails.TVID_Bedrag}, {tblTV_Sessies.TVSE_Begintijd}, "daily")

So I believe the formula in the subreport is not correctly calculated.

Can you please help me further?

Many thanks,

Michel
 
Using Crystal syntax (make sure that's what is selected in the formula box), you must leave in the colon. The error message suggests that the datattype of {tblTV_Stortingdetails.TVSD_Bedrag} is not numeric. If it is a currency, change the formula to:

whileprintingrecords;
shared currencyvar subamt := sum({tblTV_Stortingdetails.TVSD_Bedrag});

Note that you can name the variable anything, i.e., you could change "subamt" to "x" or anything you wish.

-LB
 
I'm almost getting there, but not quite.

You were right about the currency! Now I have no error, the colon is there and when I preview the subreport only, the correct values are displayed on the subreport.
So far so good!

But when I view the main report, the shared variable does not have the value it should have, but remains zero.
I tried to put the variable in different sections, but the result stays the same.
This is the code in my main report:

whileprintingrecords;
shared currencyvar StortingenPerDag;
StortingenPerDag - Sum ({tblTV_Inkomstendetails.TVID_Bedrag}, {tblTV_Sessies.TVSE_Begintijd}, "daily")

I only get the value after the "-" in negative. So I assume that the variable StortingenPerDag remains zero, although it is passed from the subreport with the correct value when I view the subreport.

What could be the problem?

Many thanks for your help and greetings,

Michel
 
First, you have to place the first formula in the report footer of the subreport. Then the formula for the calculation MUST be in a section below the one in which the subreport is executing.

I think you should explain in which section the subreport is located and then where you are placing the reset and calculation formulas in the main report.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top