Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alternating background colors in a crosstab report 1

Status
Not open for further replies.

buck149

Programmer
Jan 22, 2007
54
US
how could I format the background color in a crosstab report so that each every other column or row will display a different color?
 
Please see thread149-1213140 and thread767-1154875.

-LB
 
a friend of mine offered an easier way to do this and he was using the following formula:

Global BooleanVar colorrow := not(colorrow);

if colorrow
then white
else silver
 
Using this formula to format the cell fields will actually give a checkerboard effect rather than alternating rows.

Gary Parker
MIS Data Analyst
Manchester, England
 
This is a nice solution that works if there are no column fields or if there is a column field and there is an even number of rows. If there is a column field and an odd number of rows, you get a checkered affect. I've used something similar, but because of this caveat, it isn't the best solution. I would be interested in knowing if your friend has a remedy for this issue and what it might be.

-LB
 
I couldn't resist playing around with this and eventually I managed to get it to give the desired effect using 3 separate formulas for eacg crosstab object

Formula 1 for formatting the row labels, this is basically the formula supplied by buck149

Code:
Global BooleanVar LabelColor := Not(LabelColor);

If LabelColor Then
    CrNoColor
Else
    Color(238,238,238)

Formula 2 for formatting the cells , replace {RowGroup.Field} with the filed used as rows in your crosstab

Code:
Global NumberVar CountRow := CountRow + 1;

If CountRow Mod DistinctCount ({RowGroup.Field}) = 0 or 
    (CountRow Mod DistinctCount ({RowGroup.Field})) Mod 2 <> 0 Then 
    CrNoColor    
Else
    Color(238,238,238)

Formula 3 , once again the same formula as used for formatting the labels but with a different counter

Code:
Global BooleanVar TotalColor := Not(TotalColor);

If TotalColor Then
    CrNoColor
Else
    Color(238,238,238)

HTH



Gary Parker
MIS Data Analyst
Manchester, England
 
Gary,

Since I only wanted to make alternating colors for rows, I used your second formula. Somehow, it was not stable by which I meant that for the first few columns (5, actually), the alternating colors for rows lined up without any problems but it went weired after that. I am still trying to figure out why.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top