Alternate Shading

G

Guest

I have a report which lists products that have been ordered by customers. To
improve readability, I'm trying to get the report to print with alternate
shading where I have a line of product with the background shaded and the
next unshaded and so on. Is that possible in Access? Thanks.
ck
 
R

Rick B

Please search for your answer first. This has been asked and answered many
many amny times in this news group.
 
N

Nikos Yannacopoulos

Dear CK,

There are two ways to do it, one with VB code (the "proper" way), and one
without, with a little trick. The funny thing is the code one is a lot
slower, and it becomes apparent in big reports!
Both ways rely on a line counter in the detail section of the report. To do
that, while in design view, add a new textbox, call it txt Counter and set
its ControlSource property to =1, and its Running Sum property to Over Group
(or over all, depending on how you want it to behave)! You can also set its
Visible property to No, so it doesn't show or print.
This done, the background is changed by examining the residue of the value
in txtCounter divided by 2 (which will always be 0 or 1).
Doing it through code, you would need something like:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Counter Mod 2 = 0 Then
Me.Detail.BackColor = 12632256
Else
Me.Detail.BackColor = vbWhite
End If
End Sub

behind the Format event of the detail section (works great but slow).

Alternatively: add another unbound textbox in the detail section, with its
ControlSouce property empty (delete its label), and drag it to cover the
entire detail section area. While it's selected go Format > Send to Back (so
the data controls will always be on top), and then go Format > Conditional
Formatting; in the dropdown under Condition 1 select "Expression is", and
type the following expression next to it:

[txtCounter] Mod 2 = 0

Then right underneath, select the background colour you want ("bucket"
tool), and you're done!

HTH,
Nikos
 
G

Guest

Thanks Nikos for your detailed explanation. I'm using the VB code you
suggested and it works great. The report is actually an invoice with several
line items but seldom exceed 3 pages so I've not been hit by the slow
peformance.
ck
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top