[FAQ's: OD] How do I color alternating rows on my report (Greenbar effect)?
Quote:
Greenbar:
A style of fanfolded continuous-feed paper with alternating green and white bars on it, especially used in old-style line printers. This slang almost certainly dates way back to mainframe days.
Greenbar formatting on a report is very easy to do with only a few lines of VBA code. It makes reading reports and printouts much easier.
Once you have created your report you will want to make sure all the controls in the Details section have a Transparent background applied via the Properties window. After that is done all that is left to do is add the code that formats the Background property of the Details section in an alternating fashion with a light green color or any other color you wish.
To view the Class module code (CodeBehind) of your opened report:
http://vbforums.com/attachment.php?attachmentid=47986
Preview or the completed report with Greenbar effect:
http://vbforums.com/attachment.php?attachmentid=47987
Access 2003 VBA Code Example:
VB Code:
Option Explicit
Option Compare [color=navy]Database[/color]
Private miCount As Integer
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'Determine if we are on an even or odd record.
If miCount Mod 2 = 1 Then
'White
Detail.BackColor = vbWhite
Else
'Light Green
Detail.BackColor = RGB(228, 255, 223)
End If
miCount = miCount + 1
End Sub
Private Sub Report_Open(Cancel As Integer)
miCount = 1
End Sub