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

How share variable between subreport and main report? 1

Status
Not open for further replies.

alexbelovtt

Programmer
Nov 15, 2005
51
US
I use Crystal 11 and visual basic.
I have main report that contains several subreports.
Some of subreports have section where I do display special characters. If that character displayed I do need display explanation on main report Page footer:
Main report:
Subreport 1
Subreport 2
Subreport 3 (with special characters)
Subreport 4
Subreport 5.
Main report page footer:
Here I do need display explanation of special characters if those characters have be displays in page of Subreport 3
I do need:
1.Reset variable in main report Page Header to 0
2. Change variable in Subreport 3 if special character printed to be more than 0
3. Read value of variable in main report page footer to display or not explanation.
Whatever I try, changes to variable are not visible in between main report and subreports.

To accomplish that I create formulas:

1. Page header of main report
Code:
WhilePrintingRecords;
Shared NumberVar LineCount:=0;

2. In section of subreport 3, where those characters may be printed:
Code:
Shared NumberVar LineCount;
IF {Required_Flag} = 'Y' THEN  
LineCount := LineCount + 1;
LineCount
3. In page footer of main report I try to read that variable:
Code:
whileprintingrecords;
Shared NumberVar LineCount;
LineCount := LineCount;
Sure I do something wrong.
Any suggestion will be helpful.
Thank you.
Alex.
 
The last formula should be:

whileprintingrecords;
Shared NumberVar LineCount;
LineCount

But you don't explain where in the main report your subreports are, such as a group, the details, or?

Otherwise I think that the formulas are fine, it's a question of where you are doing things. In section of subreport3 should state WHERE, it doesn't take but a second longer to clearly define this.

-k
 
Thank you.
I’m sorry for not full explanations.
Each subreports set in detail section of main report, there is no group in main report.
Variable in section of subreport 3 is changed; I can read it inside of subreport.
Group Section of subreport 3, where I do calculation that is a group header.
Structure of Subreport 3 is:

Report Header (here reset variable to 0 works)
Page header (here reset variable to 0 works)
Group header 1
Group header 2 (in that group I have formula 2)
Detail 1
Detail 2
Report footer (here variable is visible)
Page footer (here variable is visible)

I try correction to formula, but it’s doesn’t works.
Looks for me as variable in page header of main report is not visible for subreports (in detail sections of main report), and then variable in subreports (detail sections of main report) are not visible for page footer of main report.

Subreport 3 (with special characters) is not in last detail section of main report, it has two more detail section after, with subreports in each.

I read somewhere that subreports variables are visible only in next section of main report. And I try to read that variables in next section, hoping then I can access it in page footer, but it’s doesn’t work easer.

Any suggestion will be helpful.
 
Where are you displaying the shared variable in the main report?

The variable will only work AFTER the subreport has completed.

And remember that since the subreports are in the details, which sounds like a bad design, the subreport will run again for every row in the main report.

Right click the details section that the subreport is in, and select insert section below, then palce your display formula in there.

-k
 
Thank you.
Main report in my design is only container used to show or hide combination of subreports depends of business logic. May be I’m wrong, but that only way I can accomplish 16 different data sources in one report (main) and display all of them or any combination.

If I add section below and suppress it, could I read that variable in page footer?
What formula could I use in page footer?
Will same formula work:

whileprintingrecords;
Shared NumberVar LineCount;
LineCount

 
Your description of the subreport is confusing, since there are no page headers and page footers in a subreport. If you want the variable to display in the main report page footer, then I think you should have the reset in the main report page header (not somewhere in the subreport). Note that the variable will only display after the complete subreport has executed, so if the subreport is more than one page, the variable will only display a non-zero value in the page footer of the second page.

-LB
 
Thank you.
You are absolutely right. Next Page has result.
Do you know any way to get that value on previous page?
Now about subreports confusion.
I use main report as container only.
Only way to add subreport (as far as I’m know) is – right click on section and choose insert – subreports.
I just test all three ways – form wizard, form existing report and form designer.
All result are same - subreports doesn’t have page header and footer.
If I can insert subreports with page footer and header, then I do not need all those formulas.
I try to play with add section below on subreport, but that only inserts detail or report footer a.

 
There isn't a way to pass the results to the first page, since the subreport hasn't finished executing. You could however, create a fake page header and footer in your subreport. To create the page header, create a formula that is true for all records:

whilereadingrecords;
1

Insert a group on this formula and check "repeat group header on each page". Make sure this is your group #1. Now you can remove the group name and use this as your page header. The page footer is a little more complex. First create a formula {@linecnt}:

whileprintingrecords;
numbervar linecnt := linecnt + 1;

Place this in your subreport in the detail section. Then note the value of linecnt at the bottom of the page. Let's say that the value is 50.

Create a second formula:

whileprintingrecords;
numbervar linecnt := 0;

Place this in the fake page header.

Next insert a second detail section detail_b. Place your page footer fields in this section. Then go to the section expert->detail_b->suppress->x+2 and enter:

{@linecnt} <> 50

Also format the detail_b section->new page after->x+2:

{@linecnt} = 50

Since you have other sections besides the detail section, you actually need to follow the above for all sections, in case the last section on the page is a group section, but I thought it would be simpler to explain just using the detail section. You would place {@linecnt} in all sections, insert second sections to each section that might end the page (if you have selected "keep group together", the group header section will never end the page), add suppression formulas for all second sections as above, and new page after sections as above. The page footer fields would need to be placed in each potential page footer.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top