first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

Code: Shading Alternating Groups of Rows in a Report

The rows produced in the detail (Section(0)) of an MS Access report can be formatted on the fly using code in the Format event of the report. The "secret" is the economical use of the modulo function:

Sub Detail2_Format (Cancel As Integer, FormatCount As Integer)

lngCountRows = lngCountRows + 1

If lngCountRows Mod 5 = 0 Then ShadeRows (YELLOW)

If lngCountRows Mod 10 = 0 Then ShadeRows (WHITE)

End Sub

Where ShadeRows() is a user-defined procedure that takes the form:

Sub ShadeRows (lngColor As Long) Section(0).BackColor = lngColor Me![<control name>].BackColor = lngColor 'etc. End Sub

Note that YELLOW and WHITE are declared as Long datatype constants at the module level:

Dim lngCountRows As Long
Const YELLOW& = 65535
Const WHITE& = 16777215
mod date: 1998-02-11T21:57:07.000Z