There may be times when you would like to format alternate row colours when creating a Microsoft Access report. This can 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 create this, all that is required is that the following code is added to the reports Detail On_Format Event Procedure:
Private m_RowCount As Long
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) m_RowCount = m_RowCount + 1 If m_RowCount / 2 = CLng(m_RowCount / 2) Then Me.Detail.BackColor = 15263976 'Change value to the color you desire Else Me.Detail.BackColor = 14811135 'Change value to the color you desire End If End Sub
The following shows an example of the above code in action in a Microsoft Access Report:
Microsoft Access report showing alternate row colours
This code sample should work in Microsoft Access 97, 2000, XP and 2003.
Check out Creating Alternate Row Colours in a Microsoft Access 2007 Report to see how we can do this using Microsoft Access 2007.