Solved

Crystal Subreports with Variable fields

Posted on 2013-12-10
1
422 Views
Last Modified: 2013-12-11
I have 2 reports that I need to connect and I know it will probably need a variable setup.  It has been a really long time since I've need to do it and I just a blank.

The main report pull the payroll check detail for a "specific check date".  The second report totals the YTD gross payroll for the employee at the time of the "specific check date" using sums from 01/01/13 to the check date.  

I need to connect (I guess by subreport) and have a shared variable that I can then put that YTD Gross Payroll on the line with the check.  The common field in the 2 reports is the employee ID number.  

Can someone help me get started with this?
0
Comment
Question by:nursecore
1 Comment
 
LVL 34

Accepted Solution

by:
James0628 earned 500 total points
ID: 39710977
FWIW, it might be more efficient if you could create a query (eg. in a stored procedure or a CR Command) that would calculate the YTD, and use that query as the datasource for the report, rather than create a subreport that's run for each employee/check.

 For the subreport, I would create a report that reads the YTD data and give it parameters for the emp ID and check date.  It would also presumably need to calculate the starting date (eg. 01/01/13) based on the check date.  Use the parameters, and the calculated starting date, in the record selection formula.

 Create a formula like the following and put it in the subreport header or footer:

Shared NumberVar YTD_gross;
YTD_gross := Sum ({gross pay field})

 That's the basic idea, although it may not be quite that simple if you don't just have a single "gross pay" field.

 Insert that report as a subreport, and link your emp ID field and the check date to the subreport parameters.

 You can suppress the fields/sections in the subreport, and then use the "Suppress blank subreport" option in the subreport format, so the subreport doesn't produce any output on the report.  If you just suppress the subreport, or the section that the subreport is in, then the subreport won't be run.

 In the main report, create a formula similar to the following and put it in the report header.

Shared NumberVar YTD_gross;
""

 The "" is simply so that the formula doesn't produce any visible output on the report.  You could also suppress the formula field, or the section.

 In a separate section _after_ the one that contains the subreport, you can use YTD_gross in a formula to get the value from the subreport.

 Depending on your data and report structure, you may need to reset YTD_gross to 0 somewhere (eg. in a group header for each employee).  Otherwise, if an employee doesn't have any "history" for the subreport to read, they could get the total from the previous employee.  Like I said, whether or not that could happen will depend on your data and report structure.  I just wanted to mention it.

 James
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question