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

Compare a field from main report against a field from a subreport on CRYSTAL REPORT

Status
Not open for further replies.

Ajmal N

Technical User
Jun 16, 2021
7
0
0
GB
I was wondering if there is a way for comparing a field from the main report against the a field from a subreport.
My main report is pointing to the current month data and the same report is pointing to the previous month data in the sub report.

I need to do something like:
IF SubReportStatus(previous month) = '1-30 days' AND MainReportStatus(Current month) = '31-60 days' THEN "Worse" ELSE IF
IF SubReportStatus(previous month) = '61-90 days' AND MainReportStatus(Current month) = '91+ days' THEN "Worse"

etc etc.

It would be really helpful and really appreciated to know if there's a way this can be done.

Many Thanks
 
You would have to put the value of the shared report field in a shared variable (i.e, in a formula). Then it will be visible in the main reports (in any section after where the sub-report is).
 
Hi Kray,

When you say "put the value of the shared report field" what do you mean by that, would you be able to provide an example? I'm fairly new to Crystal so need assistance with formulas.

Please let me when possible as I have been on this project for a while and need to complete soon.

Many Thanks
 
So in a formula you would set up something like this in the sub-report

Shared stringvar somevalue := {field value}; //You could also use the result of another formula. I just used the stringvar as an example. I do not know what data type you want to pass.

In the main report in s section after the where the sub-report is (and do not suppress the section where the sub-report is or it will not execute). Another formula

Shared stringvar somevalue; // The value is now available to the main report. At this point you can do whatever comparison you need with the main report values.
 
Kray,

The status field has the following info, 1-30 days, 31-60 days, 61-90 etc.

What I need to do is, pass this value to the main report from the subreport so it allows me to compare the subreport and main report Status field.
e.g.
IF SubReportStatus(previous month) = '1-30 days' AND MainReportStatus(Current month) = '31-60 days' THEN "Worse" ELSE IF
IF SubReportStatus(previous month) = '61-90 days' AND MainReportStatus(Current month) = '91+ days' THEN "Worse"

etc etc

The outcome needs to be on the main report as a field.

Thanks
 
Did you even try what Kray said to do?

Replace "SubReportStatus(previous month)" with the shared variable from the subreport.

Macola Software Veteran and SAP Business One Consultant on Training Wheels

Check out our Macola tools:

 
Yes, I tried what Kray said to do, also took into consideration your point of replacing "SubReportStatus(previous month)" with the shared variable from the subreport" but no luck.
 
Of course a couple of things to remember about shared variables and sub-reports. First of the sub-report or the section it is in cannot be suppressed (there are tricks that you can use to get around this issue if you do not want to see the values in the sub-report). The sub-report has to be in section prior to where you want to see the value in the main report.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top