CAPTCHA
Image CAPTCHA
Enter the characters shown in the image.
This question is for testing whether or not you are human.
  • Create new account
  • Reset your password

User account menu

Home
The Hyperlogos
Read Everything

Main navigation

  • Home
  • My Resumé
  • blog
  • Howtos
  • Pages
  • Contact
  • Search

Crystal Reports 9: Alternating Line Colors

Breadcrumb

  • Home
  • Crystal Reports 9: Alternating Line Colors

Crystal reports is lacking a great deal of functionality which seems like an obviously desirable addition. One of these items is the ability to display report results with lines whose background colors alternate, much like the fanfold computer paper of old, or for that matter a check register or just about any other traditional method of rendering data in rows. Business Objects provides a document that tells you how to go about this (C2014182) but for some report types, especially those with nested groups, this doesn't necessarily work properly.

All of these formulas are put into place using the background color formula button. In CR9 this is on its own tab in the section expert; right-click the section in design view, select "Section Expert..." and click the Color tab, then the X+2 button for background color, and paste in the appropriate formula. All of these are written in Crystal syntax, or something like it.

Their first example pertains to detail records, not groups. It reads as follows:

if Remainder(RecordNumber, 2) = 0 then Red
else Yellow

Aside from posessing a truly agonizing color scheme, this works just fine. However, it's obvious that it will only work for records, and not groups, since it uses the reserved variable "RecordNumber" (a NumberVar.) The scheme for groups is a little different. Here's an example with a more reserved selection of colors that works for group results:

if Remainder(GroupNumber, 2) = 0 then crNoColor
else Color(240,240,240)

That's nice, but sometimes you end up with groups inexplicably not shown in alternating colors. This probably has something to do with conditional suppression of group records. Instead of depending on the GroupNumber NumberVar, we will just do something similar to a manual running total:

Shared NumberVar GroupNum;
GroupNum := GroupNum + 1;
if Remainder(GroupNum, 2) = 0 then crNoColor
else Color(240,240,240)

We declare (the first time) or reference (each subsequent time) a shared-memory NumberVar called GroupNum. This can of course be any unique non-reserved name. The first time we reference GroupNum it is initialized with the default value for a NumberVar, which is 0. We then proceed to increment it by 1 before making our if-Remainder comparison. This way our first line will be shaded, which helps to distinguish it from the subject headings. This method will also work for detail records, or anything else.

database
howto
crystal reports

Matthew Johnson (not verified)

11 years 8 months ago

Permalink

Thank you, this is precisely

Thank you, this is precisely what I needed. I was unaware of the Shared option.

  • Log in or register to post comments
  • Log in or register to post comments

Footer menu

  • Contact
Powered by Drupal

Copyright © 2025 Martin Espinoza - All rights reserved