databasedev.co.uk - database solutions and downloads for microsoft access

Create Better MS Access Reports
Report Builder for Microsoft Access helps you create dynamic, professional-looking reports fast! The easy-to-understand wizard helps you with complex tasks like calculated fields, adding subreports, customizing styles, as well as grouping and sorting. Download a free trial today!

Microsoft Access Reports

Alternating Report Group Colours in a Microsoft Access Report

As we have seen in a previous Microsoft Access report article, we can alternate row colors in our Access reports. You can also add grouping to your report, which breaks related data into groups of records. We can format the report, and alternate the colours of the groups of data, which in turn will greatly aid the user who is viewing the report, by ensuring that the data is in a much more visible format.

To enable you to alternate report group colours, all that is required is that the following code is added to the On_Format Event Procedure of the reports Group Header:

The code is added to the On Format event of the GroupHeader
The code is added to the On Format event of the GroupHeader

Option Compare Database
Option Explicit
Dim blnalternate As Boolean


Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
    If blnalternate Then
        Detail.BackColor = 15263976
        GroupHeader0.BackColor = 15263976
    Else
        Detail.BackColor = 14811135
        GroupHeader0.BackColor = 14811135

    End If
    blnalternate = Not (blnalternate)
End Sub

When we run the report, this demonstrates how the grouping will appear:

A sample of the Microsoft Access report, including the grouping
Microsoft Access report showing alternate row colours

This code sample should work in Access 97, 2000, XP and 2003.

An example of this database can be found in the Microsoft Access downloads section or the Microsoft Access Reports section. This example is created in Microsoft Access 2000.