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

New and Confused

Status
Not open for further replies.

sfcmikej2

IS-IT--Management
Jan 2, 2005
1
US
Hey everyone,

I am somewhat new to Crystal reports. I have used it to develop some simple reports in the past but what I am trying to do now has me completely confused. I am using CR 8.5. I have SQL Server and Access experience and have developed many complex solutions with these tools. I am now working with a client trying to improve their reports for their business software. I am actually modifying some existing reports.

From what I can figure out I can declare a shared variable that can pass info from the main report to a subreport. Can a shared variable pass data from the subreport and how is it done?

What I am trying to do is to sum the list price of a sale in the subreport and then use that figure to calculate the difference between the list price and sale price of the entire order. The detail records are in a subreport in the details section and I want to print my calculations in the Group Footer in the main report.

Thanks,

Mike
 
It would help to know your report structure, e.g., what your groupfield is, how you are linking the subreport to the main report. Since you are placing the subreport in the detail section, I'm guessing you are linking on {table.itemno}, and it sounds like the sale price is in the main report and the list price is in the subreport.

If I'm guessing right, then you would need to accumulate the subreport results in the main report before performing the calculation in the group footer.

In the subreport, create a shared variable by going to the formula editor->new and entering:

whileprintingrecords;
shared numbervar listprice := {table.listprice};

You MUST place this formula on the subreport canvas (in the details section in this case). Then in the main report, create a formula {@accum}:

whileprintingrecords;
shared numbervar listprice;
numbervar accumlistpr := accumlistpr + listprice;

Insert a second detail section (detail_b) by right clicking on the "D" area in the gray area to the left of the preview screen->insert section below. Place {@accum} in the detail_b section, since shared variables MUST be placed in a section below the one in which the subreport is located. You can go to the section expert and suppress detail_b so that it does not display. Then create a display formula {@display} for the group footer:

whileprintingrecords;
numbervar accumlistpr;

Or, to perform the calculation, create a formula like the following, also to place in the group footer:

whileprintingrecords;
numbervar accumlistpr;

accumlistpr - sum({table.salesprice},{table.groupfield})

If you have any nulls in the subreport, you would also have to create a reset formula to be placed in the main report group header, so that the value from the previous execution of the subreport does not carry forward:

whileprintingrecords;
shared numbervar listprice := 0;

Shared variables can be created in both the main report and subreport, but it is the position of the formulas that is critical. If in the main report, the shared variable must be defined in a section above the subreport where it will be used, while if a shared variable is created in the subreport, the formula referencing it in the main report must be located below the subreport. It is also important to note that the formula defining the shared variable must be placed on the report canvas.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top