?
Solved

Alternating Colors Issue Crystal Reports

Posted on 2010-11-17
20
Medium Priority
?
526 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 668 total points
ID: 34155424
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
ID: 34155537
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
ID: 34155626
if <put second formula name here> mod 2 = 0 then
   crNoColor
else
{@ICONTeal}
0
Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

 

Author Comment

by:nobile00
ID: 34155711
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
ID: 34155749
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
ID: 34155915
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
ID: 34156055
do you by the chance suppres some groups based on some conditions?
0
 

Author Comment

by:nobile00
ID: 34156327
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
ID: 34164978
Any other suggestions to get the alternating colors to display correctly.

Thanks in advance
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 34178564
How are you suppressing the groups?

mlmcc
0
 
LVL 35

Assisted Solution

by:James0628
James0628 earned 668 total points
ID: 34178905
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
ID: 34189082
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 101

Expert Comment

by:mlmcc
ID: 34194089
Could you post the report?

mlmcc
0
 
LVL 35

Expert Comment

by:James0628
ID: 34194643
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
ID: 34196432
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 101

Assisted Solution

by:mlmcc
mlmcc earned 664 total points
ID: 34196989
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 35

Expert Comment

by:James0628
ID: 34202754
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 101

Expert Comment

by:mlmcc
ID: 34220316
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
ID: 34260264
Thanks to all everything is working great!!
0
 
LVL 35

Expert Comment

by:James0628
ID: 34264699
You're welcome.  Glad I could help.

 James
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

750 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