Print Page | Close Window

How to pass value from main report to sub report

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=9568
Printed Date: 06 May 2024 at 5:56pm


Topic: How to pass value from main report to sub report
Posted By: madhugangaraju
Subject: How to pass value from main report to sub report
Date Posted: 31 Mar 2010 at 7:35pm
Hi All
iam designing a report which includes subreport every thing is fine but i have to display the grand total in subreport which includes the main report total field . So how i get the main report total in to the sub report
Thanks in advance

-------------
madhu



Replies:
Posted By: E-T-M
Date Posted: 31 Mar 2010 at 9:46pm
You have to use shared variables.

Declare a shared variable in a formula of your main report
e.g.
shared numbervar NAME := <YOUR FORMULA>


Now you can address this shared variable in your subreports' formulas.


Posted By: madhugangaraju
Date Posted: 31 Mar 2010 at 10:00pm
thanks for your reply
but how should i use this formula field in the subreport
thanks in advance

-------------
madhu


Posted By: E-T-M
Date Posted: 01 Apr 2010 at 5:33am
Here's a detailed example:

1. In main report create a formula, name it, edit it with the formula editor as follows:
shared numbervar NAME := {table1.field1} + {table1.field2}
Save formula.
note that you should replace the name and type of variable and a formula with ones of your own


2. Now create a formula in your subreport, name it, edit it with the formula editor as follows:
Shared numbervar NAME;
NAME
Save formula.

3. Use formula created in step 2 in your report.

This way you will have a {table1.field1} + {table1.field2} result from main report transferred to your subreport.


Posted By: madhugangaraju
Date Posted: 01 Apr 2010 at 9:00pm
Thanks for your reply
i tried it but it is not working
In my subreport i created the formula field and just typed the 'NAME' which is the variable declared in main report and it is showing error
I tried in the following way
1.In Main Report I created a formula field 'TEST' and declare the following code like:

shared numbervar NAME:={DTM200QTY}


2.In sub report I Created a formula field 'TEST' and declare the following code like:

NAME //which is shared variable in main report


It is showing error then i change this formula in this way in the sub report

shared numbervar NAME:= NAME//variable from main report  i think so 

NAME-{DTM20QTY}//sub report total field

i place it in sub report it is showing only the sub report field value {DTM200QTY} but not the difference of the shared variable and the subreport field
how should i get this

-------------
madhu


Posted By: E-T-M
Date Posted: 01 Apr 2010 at 10:35pm
OK
I've tested and it works
Main Report
Shared numbervar NAME := 45

Subreport
Shared numbervar NAME;
NAME + 50


Note that subreport is processed after the main report, so it's easier to pass values from main report to subreport. Vice versa is also possible but is more painful :)


Posted By: madhugangaraju
Date Posted: 01 Apr 2010 at 11:22pm
Thanks
Its working fine thanks a lot
and another issue iam facing how to fix the size of the detail section means
it is fixed for 12 records and if the 9 records are printed then also detail section should be in the same size
thanks in advance

-------------
madhu



Print Page | Close Window