Solved

Alternating Colors Issue Crystal Reports

Posted on 2010-11-17
20
515 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:nobile00
  • 8
  • 4
  • 4
  • +1
20 Comments
 
LVL 2

Accepted Solution

by:
vetaldj earned 167 total points
Comment Utility
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 Comment

by:nobile00
Comment Utility
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
 
LVL 2

Expert Comment

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

Author Comment

by:nobile00
Comment Utility
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
 
LVL 2

Expert Comment

by:vetaldj
Comment Utility
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 Comment

by:nobile00
Comment Utility
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
 
LVL 2

Expert Comment

by:vetaldj
Comment Utility
do you by the chance suppres some groups based on some conditions?
0
 

Author Comment

by:nobile00
Comment Utility
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 Comment

by:nobile00
Comment Utility
Any other suggestions to get the alternating colors to display correctly.

Thanks in advance
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
How are you suppressing the groups?

mlmcc
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 34

Assisted Solution

by:James0628
James0628 earned 167 total points
Comment Utility
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 Comment

by:nobile00
Comment Utility
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
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Could you post the report?

mlmcc
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
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 Comment

by:nobile00
Comment Utility
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
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 166 total points
Comment Utility
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
 
LVL 34

Expert Comment

by:James0628
Comment Utility
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
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
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 Closing Comment

by:nobile00
Comment Utility
Thanks to all everything is working great!!
0
 
LVL 34

Expert Comment

by:James0628
Comment Utility
You're welcome.  Glad I could help.

 James
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now