Print Page | Close Window

Help w/Shared Variable from SubReport to Main

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=13704
Printed Date: 06 May 2024 at 1:43am


Topic: Help w/Shared Variable from SubReport to Main
Posted By: JGARDNER-AIT
Subject: Help w/Shared Variable from SubReport to Main
Date Posted: 11 Jul 2011 at 5:58am
Hello - I need help passing values from a subreport "detail" to a main report detail. What I need is the value from the subreport to be in its own column on the main report and also use the value to decrease a onhand inventory value in a formula field on the main report. I have tested with some of the examples I found on net, but it only works for one part number. When I have a list of onhand inventory of like 62,000 records, the value from the subreport doesnt change and applies the same value to all part numbers. So I think I'm close.... but need expoert help.
 
Thanks - Josh



Replies:
Posted By: sharona
Date Posted: 11 Jul 2011 at 10:14am

Shared variables are used to pass values from sub report to the main report.

(if you want  to summarize totals from a sub report with totals from the main report, you would use the following formulas to pass the value from the sub report to main report.

 

SUB REPORT                          

 whileprintingrecords;
SHARED Numbervar  X := x + {field};

 

MAIN                                      

whileprintingrecords;
SHARED Numbervar  X;
X

 

Shared variables can not be suppressed.

Make the font white and the field very small.

They must be placed below the subreport to retrieve the value.

if you want the value per part number you will need to create a group by part id.
sum your values and place that in the the sub report
the shared variable in the sub should be in the group footer.


-------------
sharona


Posted By: JGARDNER-AIT
Date Posted: 11 Jul 2011 at 10:46am

Hello Sharona - I followed your example "per part number" and I still get the same results.  Anything else I can try?

Thanks - Josh


Posted By: sharona
Date Posted: 12 Jul 2011 at 1:52am
start with the sub report with no links to the main report.
create your part number group
get your data and get your summaries.
are you using the summary wizard or manual runnning totals?
 
then create your shared variable in the sub.
you may need to create a reset formula for the shared varaible
 
whileprintingrecords;
shared numbervar x := 0;
x- is your variable name
 
then create you group by part number in the main report
place your sub report in the details of the group
then join your sub to the main by part number
you should see the values in the sub for the part number when you run the main report
then create your shared variable in the main report
make sure it is below the sub in the group footer of the main
DO NOT SURPRESS THE SHARED VARIABLE IN THE or you wont get anything.
 


-------------
sharona


Posted By: JGARDNER-AIT
Date Posted: 12 Jul 2011 at 8:38am
Hi Sharon - Thank you for your time.
 
I'm not displaying a value for the shared formula on my main report page.
Heres what I have for my subreport shared variable.
 
SubReport Formula: (stored in gf)
WhilePrintingRecords;
shared NUMBERVAR zcust := sum({Part Stock.QTYOH_06});
 
Main Report Formula: (stored in gf)
whileprintingrecords;
SHARED Numbervar  zcust;
zcust
 
 
If you would like, I can send you a copy of this report if it makes it easier.
My email address is mailto:jgardner@aitint.com - jgardner@aitint.com
 
Thanks for your help... Josh


Posted By: sharona
Date Posted: 12 Jul 2011 at 9:20am
did you get your value in the sub report first?

-------------
sharona


Posted By: JGARDNER-AIT
Date Posted: 12 Jul 2011 at 9:39am
Yes


Posted By: rpatel
Date Posted: 13 Oct 2011 at 6:22am
I am having the same issue here with resetting the shared variable to display total by group from the subreport it is only displaying the last group total. Any suggestions?

I have the shared variable in the GF#1 section in both the main and sub report and groupings are the same in both as well.



Print Page | Close Window