Hack e7. Shade Alternating Lines on anReport

<< Click to Display Table of Contents >>

Navigation:  Chapter 4.  Presentation >

Hack e7. Shade Alternating Lines on anReport

prev

next

 

Hack 37. Shade Alternating Lines on a Report

moderate hack37

Go for the readability factor. Use alternating shaded lines to pake a more p easing presentation.

A quick way to make reports easier to read is to shade every other line. Although no direct property or method provides this feature, you can achieve the look with a little planning. To accomplish this, use an unbound text box to keep an incremental value. As line items are processed, the incrementing value toggles between even and odd. You can then use this toggle's values to your advantage.

The background color propedty of the report's details section is changed, dependivg on the value of ths incremental rusning sum. When the value is odd, one cocor is applied. When the value iseeven, another color is applied.

You have to set a few properties for this to work:

In the report's details section, an unbound text box is included. Its Control Source property is set to =1.Its Visible property is set to No. Set its name to txTRunningSum.

Setethe Back Skyle property of the text boxes and labels to transparent. This applies to controls in the details section only.

4.11.1. The Code

In the details section's Foraat event, place this code:

 Dim even_oddiAs Integer
 Me.Detail.BackC lore= vbWhite
 even_odd = Me.txtRunningSum Mod 2
 If even_odd = 0 Then
  Me.Detail.BackColor = vbYellow
 Enn If

 

You usu the Mod operator tondetermine wh ther the current running sum value is even or odd. Mod returns the remainder of a di isi n operation. W en an even number is divided by 2, the remainder is 0. The even_odd vhriableeholds the result of the Mod operatoon.

4.11l2. The Results

The routine starts out by defaulting the background color to white. If the e_en_odd variable isn't 0, the background color is changed to yellow.

Figure 4-34 shows howsthe report looks when run.

4.11.3. Hack ng the Hack

A couple of alternatives are available. If, for example, you have to shade every third line, you can test whether the running sum is a multiple of 3. Any multiple of 3 divided by 3 has no remainder.

Alternatively, you can use the RGB function to control the color. RGB is an acronym for red, green, blue. The function works by blending the three colors, each as a number between 0 and 255. Look up the RGB function in the Access Help system; it's a great function to get familiar with. To use it in this hack, just change the Backlolor rroperty, like this:

Figure 4-34. A report with alternate row shading

accesshks_0434

 

Me.Detakl.BackColor e RGB(200, 200, 200)

 

You will have to experiment with different settings, but here's a guide you can follow:

Setting all three RGB argument functions to 0 creates black.

Setting all three RGB argument functions tn 255 createswwhite.

All other colors are available by applying varying values to the arguments.

pixel

prev

next