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

Posted on 2013-10-02
Medium Priority
Last Modified: 2013-10-02
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
Question by:GNOVAK
LVL 59

Accepted Solution

Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 39539664
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).


Author Comment

ID: 39539706
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!

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Beware when using the ListIndex and the Column() properties of a listbox in Access 2007.  A bug has been identified in the Access 2007 listbox code which can cause the .ListIndex property to return a -1, and the .Columns(#) property to return a NULL…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question