how do you shade alternating lines in a tabular report

P

Paul

Lightly shading alternating lines in a tabular report can create a nice
visual display making it easier read the information in a report, but I
can't figure out how to do it.

Could someone please tell me how I can accomplish this?

Thanks in advance,

Paul
 
J

Jeff Boyce

Paul

.... using which version of Access? The most recent (A'07) offers this as a
formatting option.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
P

Paul

Thanks for the reply, Jeff.

I'm sorry - I should have mentioned that I'm using Access 2003.

Paul
 
J

Jeff Boyce

Paul

Try searching on-line for that topic, and checking at mvps.org/access. I
seem to recall seeing several approaches to solving this prior to MS
incorporating it into A'07.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
G

Gina Whipp

Paul,

The below will shade alternate lines my favorite color green...

Option Compare Database
Option Explicit

Dim greenbar As Boolean

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If greenbar Then
Detail.BackColor = 12181965
Else
Detail.BackColor = 16777215
End If
greenbar = Not (greenbar)

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
F

fredg

Thanks for the reply, Jeff.

I'm sorry - I should have mentioned that I'm using Access 2003.

Paul

Make sure the BackStyle of each control is Transparent.

Code the Detail Format event:

If Me.Section(0).BackColor = vbWhite Then
Me.Section(0).BackColor = 12632256 ' gray
Else
Me.Section(0).BackColor = vbWhite
End If

====
If you wish each page to start with a white row, code the Page Header
Format event:

Me.Detail.BackColor = 12632256 'Reset color to Grey so that the
' first detail line will become white

Change the colors as needed.
 
P

Paul

Works great, Fred, and thanks for the tip about how to start each page with
the same color.

Paul
 
P

Paul

This works great, Gina.

Question: I noticed that if I keep the Dim statement at module level, as
shown in your code below, the procedure works. But if I move it inside the
procedure, it doesn't work.

Why is that? I would have thought it would work inside the procedure as
well, since the sub runs each time the detail section is rendered in the
report - that is, with each row of the report.
 
G

Gina Whipp

Paul,

Since I never moved it I never noticed that and I too would assume it work
either way. Though when you think about it the report renders as an image
"all at once" so expecting it to "run" each time the Detail section has a
new record could not work as as an image it renders "all at once".
Interesting...

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
D

Douglas J. Steele

If you declare the variable inside the procedure, it will be reinitialized
(to False, in this case) each time the procedure is invoked. In other words,
it would not remember the value it had the previous time the routine was
invoked.

You should, however, be able to declare the variable as Static so that it
keeps its value:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Static greenbar As Boolean

If greenbar Then
Detail.BackColor = 12181965
Else
Detail.BackColor = 16777215
End If
greenbar = Not greenbar

End Sub
 

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