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

Shared Variable from Subreport 1

Status
Not open for further replies.

kcoleman26

Technical User
Oct 26, 2007
66
US
Crystal 2008

I am not sure a shared variable is what I need but I think it is I just can't seem to make it work.

I have a main report that groups reservations and calculates the a total for records and revenue.

I have a sub report that groups the reservations the same way as the main report but calculates room nights for each group.

I want to take the totals of each group from the sub report and have it match up with the groups on the main report so that I can see all three calculations on one line for each group.

Desired Result of Main Report
{Reservation Group} {Total of Records} {Total Revenue} {Total Room Nts}from the sub report.

Thanks,
KC
 
So what is your problem?

NB - If you want to display Shared Var from SubRep this must execute before the point where you want to display on main report.

Ian
 
The value of a shared variable is not available until the section after the section that holds the subreport. Does that help?

Note that you can always insert a section below any existing section, you find the option on right-click.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 11.5 with SQL and Windows XP [yinyang]
 
In My SubReport
WhilePrintingRecords;
Shared NumberVar myTotal :=sum ({@f_Room Nights})

In My Main Report
WhilePrintingRecords;
Shared NumberVar myTotal;
myTotal

I have my subreport in the report header of the main report I am getting a total when I insert that formula field into the report but it is totaling all of the Room Nights together for each row.

I guess I am not sure how to reset myTotal in the formula for each group.

Thanks,
KC
 
Therein lies your problem ;-)

The subreport needs to be in Group Header and linked on the group Field.

To be safe add a reset for your var in the subreport header.

Ian
 
Another option is not to use a shared variable , but instead simply place the subreport in the same section as your other fields (group header or footer) and suppress alls sections with the sub except the one containing the desired summary. Be sure to link the sub to the main report on the group field.

-LB
 
Thanks lbass that did get the result and of course they want to see one and average.

Is there anyway to divide the summery in the sub report by a summery in the main report.

I may need to rethink this entire report. I went this way because of the way my data pulls in this report. I am joining three different databases and it gives me one line for each Transaction and an amount with that transaction however, I could have one person with several transactions creating multiple lines.

I need to calculate rm nts which I subtract departure - arrival. When I do this is puts the room nights on each record and when I try to sum rm nts for the group it adds the room nights for each record. I tried to put a group on the persons customer id but it still summed the rm nights for all of the records. Is there a way to only use the sum of room nights for each customer id.

I hope that makes sense.

Thanks,
Kerry
 
I'm assuming you are talking about within the subreport? What fields are you grouping on? Are they the same as the groups in the main report? Did you link the sub to the main report on the group fields? You can use a running total that evaluates on change of your inner group. It should be placed in the footer section where you want the result displayed.

Not sure what you mean by:
they want to see one and average.

If you need to do a calculation with a subreport result and a main report field, you must use a shared variable.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top