Online Book Reader

Home Category

Access Cookbook - Ken Getz [73]

By Root 2099 0

Table 3-9. Available ScaleMode property settings

Setting

Description

0

Custom values for ScaleHeight, ScaleWidth, ScaleLeft, and ScaleTop

1

Twip (default)

2

Point

3

Pixel

4

Character

5

Inch

6

Millimeter

7

Centimeter

The DrawStyle property specifies the line type; it is set to Solid in the sample code using the acbcDSSolid constant. The available settings are listed in Table 3-10.

Table 3-10. Available DrawStyle property settings

Setting

Description

0

Solid (default)

1

Dash

2

Dot

3

Dash-dot

4

Dash-dot-dot

5

Invisible

6

Inside solid

3.12. Alternate Gray Bars on My Reports


Problem


You have some reports on which you'd like to print alternate rows with gray bars in the background. Printing these bars makes the reports easier to read, especially when there's lots of data or the report is very wide. Is there a way to create these bars in Access?

Solution


There are a number of ways to print alternate rows with gray and white backgrounds. The simplest method is to alternate the background color of the detail section for each new record. This solution shows you how to use this method to achieve the desired effect on your reports.

To create your own reports with alternating gray bars in the detail section, follow these steps:

Create your report. Because this method will fill the entire detail section with gray shading, the effect will work best if your detail section is one line high. (It will work with taller detail sections, but it won't look as good.)

Make sure that every control in the detail section has its BackStyle property set to Transparent. You can quickly change this property for all the controls in the section by marquee-selecting all the controls and then changing the BackStyle property in the properties sheet, which will now have the title Multiple Selection (see Figure 3-28).

Figure 3-28. Changing all the controls' BackStyle properties in one operation

Edit the report's module (click on the Code button on the Report Design toolbar or choose the View → Code menu option) and enter the following lines of code in the module's declarations area:

' Shade this row or not?

Dim blnShade As Boolean

Create an event procedure attached to the OnPrint event property of your report's detail section and add the code that follows. This code must be attached to the OnPrint event property because the Line method for reports will not work when called during the Format event.

Private Sub Detail1_Print(Cancel As Integer, PrintCount As Integer)

' If all three color components are the same value,

' the result will be some shade of gray (ranging

' all the way from black (0, 0, 0) to white (255, 255, 255)

Dim lngGray As Long

lngGray = RGB(221, 221, 221)

If blnShade Then

Me.Detail1.BackColor = lngGray

Else

Me.Detail1.BackColor = vbWhite

End If

' Alternate the value of blnShade

blnShade = Not blnShade

End Sub

If it matters whether the first row on a page is shaded, create an event procedure attached to the OnPrint property of the report's page header. Replace the False value with True if you want the first row on each page to be shaded.

Sub PageHeader0_Print (Cancel As Integer, PrintCount As Integer)

' Make sure the first row on the page isn't shaded.

' Use True if you want the first row on each page shaded.

blnShade = False

End Sub

Save and print the report. Every other row in the detail section will be printed with a gray background, the same size as the detail section.

Now load 03-12.MDB and open the rptGrayBar report in preview view. This report may not look very good on your screen (it depends on the screen resolution and the color depth of your screen driver), but printed it will look something like the report shown in Figure 3-29. (The exact output will depend on your printer; you may need to modify the color setting for the gray bar to optimize it.)

Figure 3-29. A report with gray bars on alternate rows

Discussion


The code shown in Step 4 relies on a module-level variable,

Return Main Page Previous Page Next Page

®Online Book Reader