Colors in subreport

Asked

Viewed 225 times

0

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

I did it this way:

In the sub Report.

Right click on the section > 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 following without color.

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

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

The sub report has been inserted in the footer section of the report leading.

I believe that RecordNumber has received 1 on account of the section where the sub-report is in the Main Report.


Details of Crystal Reports:

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

1 answer

0


That was the problem:
For Sub Relatório have been inserted into the footnote section, then RecordNumber = 1, because the footer will be "executed" only once in the Main Report, and for some reason RecordNumber in the Sub Relatório receives the value of Main Report.

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

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

Shared Numbervar x:= 0;
x;

So I dragged the formula CountSub for the section where the Sub Relatório, and suppressed it.


In the Field Explorer Sub Relatório I created a formula with the same name (CountSub) with the following code:

Shared Numbervar x;
x:=x+1;

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

So, to each item being "inserted", I will be adding +1 in x;


So,
I right-clicked in the section > Section Expert > Color tab
and inserted 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 function CountSub, that has a shared variable x implemented in the previous codes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.