Alternating Row Colours with a Twist

I have a report that allows viewing detail or summary.  
The report lines are as follows:
Report Header
Page Header
Group Header #1a
Group Header #1b
Details
Group Footer #1
Page Footer
Report Footer

For Detail
Detail line is not suppressed
Group Header #1b is suppressed

For Summary
Detail line is suppressed
Group Header #1b is not suppressed

I know how to alternate line colours in the detail, and that works fine.  However I also need to alternate line colours for the summary which is not working as planned.  I tried putting the same code in the Group Header #1b background colour code behind, but the colours don't alternate.  There is groups of two or three that are one colour and then a group of the alternate colour, etc.

How do I alternate colours on Group Headers (when Detail line is suppressed)
LVL 10
ClifAsked:
Who is Participating?
 
Kurt ReinhardtConnect With a Mentor Sr. Business Intelligence Consultant/ArchitectCommented:
Generally, speaking, the base formulas for alternating detail row colors is:

If
  Remainder(RecordNumber,2) = 0
Then
  crSilver//or some other color
Else
  crNoColor//you don't need to specify white

Open in new window


The following formula for alternating group colors is:

If
  Remainder(GroupNumber,2) = 0
Then
  crSilver//or some other color
Else
  crNoColor//you don't need to specify white

Open in new window


If you want to customize the shading further, such as ensuring that detail records in each group always start with the same shade, you would use a running total to reset the record count within each group and then use it in your detail color formula:

If
  Remainder({#GroupRecordCount,2) = 0
Then
  crSilver//or some other color
Else
  crNoColor//you don't need to specify white

Open in new window


In your case, how are you determining whether or not detail records are shown? Is this based on a parameter such as {?ShowDetail} with values of Y or N?  If so, you would use the following type of conditional formulas:

Detail section:

If
  {?ShowDetail} = 'Y' and
  Remainder(GroupNumber,2) = 0
Then
  crSilver//or some other color
Else
  crNoColor//you don't need to specify white

Open in new window


Group Header:

If
  {?ShowDetail} = 'N' and
  Remainder(GroupNumber,2) = 0
Then
  crSilver//or some other color
Else
  crNoColor//you don't need to specify white

Open in new window


~Kurt
0
 
mlmccCommented:
Try this

I don't know what you are using for the formulas but if you include the test for suppression and evaluate only when the section is NOT suppressed it might work.

If you need help, please post the formulas you are using to alternate the colors.

mlmcc
0
 
ClifAuthor Commented:
Was there supposed to be something after the "Try this"?

I have tried various methods for alternating colours, including trying setting a flag on when off and off when on.  Nothing seems to work.
One try:
If
    Remainder (RecordNumber,2)<>0
then
    crSilver
else
    crwhite

Open in new window


Another try (gLastPrintRow is a global variable):
numberVar gLastPrintRow;
If 
    gLastPrintRow = 0 
then
    (    
    gLastPrintRow := 1;
    crSilver
    )
else
    (
    gLastPrintRow := 0;
    crwhite
    );

Open in new window

0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
mlmccCommented:
Yes except my idea wasn't going to be too helpful without seeing your formulas

Does group header 1A need to alternate colors?

For the group headers, recordnumber won't work because you aren't alternating every other unless the group only has 1 record.

Unless you need GH1A to alternate try using this on GH1B

WhilePrintingRecords;
Global numberVar gLastPrintRow;
gLastPrintRow := gLastPrintRow + 1;
If     Remainder (gLastPrintRow ,2) = 0 then
    crSilver
else
    crwhite


Also add a formula to the report header
WhilePrintingRecords;
Global numberVar gLastPrintRow;
""

mlmcc
0
 
ClifAuthor Commented:
Sorry, that didn't do it.

It was, actually, very similar to another try at it I had made.
0
 
ClifAuthor Commented:
rhinok
Sorry, but none of your group alternating rows worked.  I keep getting something like the following:

NoColour
NoColour
NoColour
Silver
Silver
NoColour
Silver
Silver
Silver
Silver
NoColour
Silver
NoColour

It's different combinations depending on which code snippet of yours I use.

You are right in that I am usingt a parameter field to select whether the user sees detail or summary
0
 
Kurt ReinhardtSr. Business Intelligence Consultant/ArchitectCommented:
Those are pretty standard formulas and I even wrote a proof of concept report in Crystal Reports XI R2 against the Xtreme Sample database 11.5.  They all work perfectly.  So, there has to be something in your specific conditional formatting that's conflicting. Are you trying to have both group header and detail records colored at the same time?  In my example, it's one or the other, depending on the parameter value.

If you have access to that database, please see the attachment.

~Kurt
AlternatingColors-CRXIR2.rpt
0
 
ClifAuthor Commented:
Header and detail are not printing at the same time, so I don't care if they are coloured the same at the same time.

I finally tried the one you gave to have the colouring always start on the first item (using a running total) and that seems to have worked.

Thanks.
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.

All Courses

From novice to tech pro — start learning today.