Access 2010: Group/Detail Report shading in Report AND Print Views

After searching for ideas on how to utilize an alternating group header with a detail section, I decided to roll my own.
It works very well in the Report View. However it appears that the PAINT() is not respected in the Print Preview.  Where do I place it?

The details as they stand now:
Vars in the report:
Dim icolorCount As Integer
Dim icolor1 As Double
Dim icolor2 As Double
Dim dGroupBackColor As Double

In the Load event:
icolor1 = 15527148
icolor2 = 16777215
icolorCount = 1
Me.GroupHeader1.BackColor = icolor1

In the Private Sub GroupHeader1_Paint()
icolorCount = icolorCount + 1
dGroupBackColor = IIf(icolorCount Mod 2 = 0, icolor1, icolor2)
Me.GroupHeader1.BackColor = dGroupBackColor
<any vars in GroupHeader1>.BackColor = dGroupBackColor

In Private Sub Detail_Paint()
Me.Section(acDetail).BackColor = dGroupBackColor
<any vars in Detail>.BackColor = dGroupBackColor
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
When in doubt of where to put something, I always go for:


in that order.   OnPage is called once for the whole page, just before it's ready to be "printed", so it's nice to do things like draw boxes at that point.  However what you can do with the page is limited, since it's fully rendered at that point.  ie. You can't hide a section or change a section size.

OnFormat is next because it's fired all the time, but the drawback is that the section is still being formatted and the engine may make multiple passes through the event.   You don't know for any given OnFormat how the section will actually end up.

OnPrint is last because while it's fired when a section has been rendered and ready to print, it's not fired in all cases.

For example, when the pages property is referred to, two pass printing is enabled.  On the first pass, OnPrint is not fired, but it is on the second.   So depending on what your doing, you might not get consistent results (ie. altering the layout and counting pages on the 1st pass vs the 2nd).


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GNOVAKAuthor Commented:
Interesting - the OnFormat works like the Paint for preview.
If I have it in both spots: Group_Paint, Group_Format  and Detail_Paint, Detail_format
works like a champ!
Excellent! Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.