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

Shared Variables & Sub Reports

Status
Not open for further replies.

ftbadolato

Programmer
Nov 12, 2002
25
US
I have a main report with 2 sub reports. I have a parameter field that I get from the user that I want to pass to all the reports. I assume I would use a shared variable to do this? I can't seem to get it to work though. I am using version 8.5. My code is as follows:

WhilePrintingRecords;
Shared varDate x := {?paramfieldvalue}

I thought I would be able to use x in all the reports by doing this, but I am not really sure WHERE to put the above code....main report, a sub report? Then where exactly in the report?

Any and all help is greatly appreciated. I am very new to Crystal.
 
You can pass the date parameter as a subreport link. Just right click on the subreport->Change Subreport Links.

Add the date parameter and link on the datefield in the subreport table.

-lw
 
I'm not sure what "links" are in Crystal, but I'll give it a go.
 
Tried to do this, and while trying I was doing some thinking....not sure if this is the way to go. I reference the parameter field in the Record Selection Formula Editor. Is this gonna make a differnece? It seems that "linking" may not be the way to go?
 
Links ARE the way to go. How you set up the linking depends partly on where the subreports are placed. Why not tell us a little bit more about the specifics of the parameters, where the subreports are placed, and your main report group structure?

-LB
 
Wow....well. Basically I created 3 reports; a cover page, an index, then a report with the details. The cover is the main report. I just followed the instructions for inserting multiple sub reports and I believe they are inserted in the page footer(s). I created an additional page footer for the 2nd sub report. Make sense?
 
I would be very surprised if you had them in a page footer. I'm guessing they are in report footer sections.

You can either go to edit->subreport links and 1) link the parameters in the main report to the related fields in the subreports, or 2) you could create the parameters also in the subreports, add them to the subreport record selection criteria, and then link the parameters to each other using the dropdown box to select {?parm} instead of {?pm-?parm} in the bottom left of the subreport links screen. If you choose the first option and are using a date parameter, check the record selection formula in the subreport to make sure that the criterion is set up correctly, i.e., you might need to change the formula so that the subreport datefield is > or < the parameter, instead of = to it.

-LB
 
You are probably right.....report footer. Here is the code in the formula editor.

(If IsNull({?StartDate}) And IsNull({?EndDate}) Then
TRUE
Else If Not(IsNull({?StartDate})) And IsNull({?EndDate}) Then
{AuthorDocumentJUNCVW.AccessionDate} >= {?StartDate}
Else If IsNull({?StartDate}) And Not (IsNull({?EndDate})) Then
{AuthorDocumentJUNCVW.AccessionDate} <= {?EndDate}
Else If Not(IsNull({?StartDate})) And Not(IsNull({?EndDate})) Then
{AuthorDocumentJUNCVW.AccessionDate} >= {?StartDate} And {AuthorDocumentJUNCVW.AccessionDate} <= {?EndDate}
)
 
If that is your record selection formula in the main report, then I would create the same parameters in the subreports, add the corresponding record selection formulas in each subreport, and then link the start and end date parameters from the main report to the same parameters in each subreport.

-LB
 
So I can "link" paramenter field from the main report to an identical parameter field in a sub report?
 
Yes. In the main report, go to edit->subreport links->add the parameter from your main report, and then in the bottom left, use the dropdown to choose {?yourparm}, not the default {?pm-?yourparm}. Repeat for your other parameters and for your other subreport.

-LB
 
OK, think I figured it out. Tell me if I am testing this right.... Assuming if the linkage worked, Crystal should only ask me for the StartDate once, correct? If so, it worked when I linked the start date from the main report to the first sub report. However, when I tried linking the StartDate from the main report to the second sub report, the StartDate to link to in the sub report was not listed in the drop down....?
 
Make sure that they are both of the same datatype, either both should be date or both datetime.

-LB
 
Spot on again. One was a datetime. So I think I got all those working. Now is there a way to link variables between subreports, or does the variable have to exist in the main report?

Off topic, but do you know how to resolve this error? It pops up at the end of the report.

"The page size was not large enough to format the contents of an object in the report.
 
I just added that field to the main report and it worked fine. I am still pondering over the error I posted though.....any ideas?
 
I don't know what you mean exactly about adding "that field". You can share variables between reports as long as the variable is created in a section above the one in which it will be evaluated in the other report.

Make sure you don't have a subreport in a page header or footer. The error message means some object is larger than a page. This often references an object like a subreport that is placed in a page header or footer.

-LB
 
I installed CR 8.5 SP 3 and the error went away. At least I am unable to reproduce it after 2 tries. The SP is supposed to address this issue, so hopefully it truly is gone. I did check and I have the sub reports in Report Footer B and Report Footer C. For some reason, Report Footer A has slashes all through it like it is unavailable?

Thanks for all your help!
 
I'm not sure what the remaining issue is. It sounds like Report Footer_a is suppressed.

-LB
 
Who knows....all seems well to me. There is a blank page that spits out at the end, but according to the knowledge base that is expected.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top