Results 1 to 1 of 1

Thread: [FAQ's: OD] How do I color alternating rows on my report (Greenbar effect)?

  1. #1

    Thread Starter
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™

    [FAQ's: OD] How do I color alternating rows on my report (Greenbar effect)?


    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:

    Preview or the completed report with Greenbar effect:

    Access 2003 VBA Code Example:

    VB Code:
    1. Option Explicit
    2. Option Compare [color=navy]Database[/color]
    4. Private miCount As Integer
    6. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    7.     'Determine if we are on an even or odd record.
    8.     If miCount Mod 2 = 1 Then
    9.         'White
    10.         Detail.BackColor = vbWhite
    11.     Else
    12.         'Light Green
    13.         Detail.BackColor = RGB(228, 255, 223)
    14.     End If
    15.     miCount = miCount + 1
    16. End Sub
    18. Private Sub Report_Open(Cancel As Integer)
    19.     miCount = 1
    20. End Sub
    Last edited by RobDog888; May 24th, 2006 at 09:39 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width