Colors in subreport

0

I'm using Crystal Reports to generate a report. This has a sub Report, where I need to add a color function to a section.

I did as follows:

In the sub report.

Right click on the > Section Expert > Color Tab

if RecordNumber = 1 then crBlue else
if RecordNumber = 2 then crRed else
crNoColor

Well, the goal is to present the first item in blue, the second in red and the next without color.

If this function were in some section in the Main Report it would work perfectly (I already tested), but the sub report does not work.

  

Only the first item receives the color (blue), but the second is left without   color.

     

The sub report has been inserted in the report footer section   main.

I believe that RecordNumber has received 1 because of the section in which the sub report is in the Main Report.


Crystal Reports Details:

DLL: CrystalDecisions.CrystalReports.Engine Description: Crystal Reports for .NET Framework Runtime Version: v2. 0.50727
Version: 13.0.2000.0

    
asked by anonymous 13.11.2015 / 13:03

1 answer

0

The problem was just this:
For the Sub Report has been inserted in the Footer section , then RecordNumber = 1 , since the footer will only be run once in Main Report , and for some reason RecordNumber in the Sub Report receives the value of Main Report .

The alternative was to use a function with a shared variable as follows:

Field Explorer Main Report I created the formula CountSub with the following code:

Shared Numbervar x:= 0;
x;

Then I dragged the formula CountSub to the section where the Sub Report was deleted and it.


Sub Report I created a formula with the same name ( CountSub ) with the following code:

Shared Numbervar x;
x:=x+1;

Then I dragged the formula CountSub to the section where I wanted to have the effect of the colors, and deleted it.

So, with each item being "inserted", I'll be adding +1 to x ;


Then, I right-clicked the > Section Expert > Color Tab and enter the following formula:

if {@CountSub} = 1 then crBlue else
if {@CountSub} = 2 then crRed else
crNoColor

Thus, the control can be done by the value returned by the CountSub function, which has a shared variable x implemented in previous codes.

    
13.11.2015 / 14:07