# Alternating Colors Issue Crystal Reports

Hi All

I am having an issue with alternating colors in a Crystal Report.  I have several groups and the alternating colors formula is in Group six the formula I am using is:

if groupnumber mod 2 = 0 then
crNoColor
else
{@ICONTeal}

However, it's works fine on pages 1 and 2 then it gets funky on page 3 where it highlights 2 rows with the same color then 2no color then 6 with color 1 without.

Is there something wrong with the formula or is there a different formula I should use so that the shading is consistent throughout the report.

Any help greatly appreciated.

Thanks
###### Who is Participating?

Commented:
Groupnumber is very tricky, at least for me :)

I use another way to solve this:
1. Create a formula with shared (or global if you like) variable

Shared NumberVar gr_cnt :=0;
True;

put it into report header and minimize it.
2. Create formula

Shared NumberVar gr_cnt;
gr_cnt := gr_cnt + 1

and place it into grop header where you want to have different color. I usually make them very tiny so you can't see it.

Now use that second formula instead of groupnumber.

In this case it will count just top-level groups and result should bre correct.

Probably not the best way but it works for me :)
0

Author Commented:
Thanks for your help.

I created the 2 formulas and placed them in the report.  I am not too clear about the last part how would the formula look without using groupnumber?

0

Commented:
if <put second formula name here> mod 2 = 0 then
crNoColor
else
{@ICONTeal}
0

Author Commented:
Thanks

The formula for the colors looks like this:

if Shared NumberVar gr_cnt;
gr_cnt := gr_cnt + 1 mod 2 = 0 then
crnocolor
else {@ICONTeal}

but I am receiving an error it highlights the semicolon on the first line and indicates keyword 'then' missing.  Do I need to put parentheses around the first part of the formula or am I missing something?

Thanks for your help
0

Commented:
Ok, you create 2 formulas, like
{@Formula1} :
Shared NumberVar gr_cnt :=0;
True;

and
{@Formula2}:
Shared NumberVar gr_cnt;
gr_cnt := gr_cnt + 1

Saved both and placed {@Formula1}  into Report Header and {@Formula2} into group header.
Then you need to modify your color formula to this:

if {@Formula2}  mod 2 = 0 then
crnocolor
else {@ICONTeal}

Sorry that I was not clear from the beginning.
0

Author Commented:
Ok I did all the above and I am still having an issue with the colors in one section which is in the middle of the report.  page 1 and 2 are fine page 3 and part of 4 not page 5 and 6 fine.

0

Commented:
do you by the chance suppres some groups based on some conditions?
0

Author Commented:
The data that needs to be alternating is in group 6 and group 1 is not suppressed but groups 2 through 5 are suppressed.
0

Author Commented:
Any other suggestions to get the alternating colors to display correctly.

0

Commented:
How are you suppressing the groups?

mlmcc
0

Commented:
Go back to vetaldj's formulas in post 34155749.

As he said, put the first formula in the Report Header, to initialize the variable.

Create the second formula, but do _not_ put it on the report.

Then use his last formula to set the color.

His instructions had you putting the second formula in the group header and using it in the color formula, which meant that it would be evaluated twice for each group header, increasing the count by 2 each time.  If you don't put the second formula on the report and only use it in the color formula, I think that will work.

An alternative would be to put the second formula in the group header (only the group header where you want to change the color) and use the variable (not the formula) in the color formula.  That way the variable is only incremented once for each group header.  My problem with that is that if you increment the variable in a formula in the group header, and check the variable in a formula that sets the color for that group header, I'm not sure which formula will be evaluated first.

The first suggestion above was just going for what was closest to what you presumably already had - Just remove the second formula from the report, but leave it in the color formula.  But if you feel like doing a bit more work, you could eliminate the second formula completely and just use this as the color formula:

Shared NumberVar gr_cnt;
gr_cnt := gr_cnt + 1;

if gr_cnt  mod 2 = 0 then
crNoColor
else
{@ICONTeal}

James
0

Author Commented:
I tried both eliminating the second formula from the group header but I get the same result not alternating on all pages.  I tried using the following formula without any other formula in the report header or group header still not alternating colors through out.

Shared NumberVar gr_cnt;
gr_cnt := gr_cnt + 1;

if gr_cnt  mod 2 = 0 then
crNoColor
else
{@ICONTeal}
0

Commented:
Could you post the report?

mlmcc
0

Commented:
I just tried it here and the basic idea works fine.

What is @ICONTeal?  Could it be changing your colors?  You could try replacing it with a color, like crTeal.

Where, exactly, did you put that formula?  I assume that it's setting the bg color for a group header section?  Is it only in one GH section?

As mlmcc suggested, you could post the report.  Sometimes there are things that just don't become clear until we see the report for ourselves.

James
0

Author Commented:
Attached is the report that I am working on.  You will see on page three the alternating colors is not working.  Also, @ICONTeal is RGB(220, 250, 250).

Thanks for all your help Invoice-ICOLIMSData112210.rpt
0

Commented:
The problem is you are conditioinally suppressing the section.

The way around this is to only change the vlue hen the section is not suppressed.
I just did

if ({BIL_INVOICE_DETAIL_S.UNIT_PRICE}) = 0 then
increment the row counter

See the attached report

mlmcc
Invoice-ICOLIMSData112210-1-.rpt
0

Commented:
FWIW, I agree with mlmcc.  You were sometimes suppressing GH6, but obviously CR is still evaluating the color formula for GH6 even when the section is suppressed, so the count was thrown off.  Changing the color formula to only increment when the section will not be suppressed seems to fix it.

James
0

Commented:
I believe Crystal firt "creates" the section then determines if you need to suppress it.  Thus the formulas all execute even though the section is eventually suppressed.

mlmcc
0

Author Commented:
Thanks to all everything is working great!!
0

Commented:
You're welcome.  Glad I could help.

James
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.