Alternating color per line in detail section

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello,

Is it possible to alternate the colour of the detail section for each line?
I hope that question is clear, if not what im looking for is the first line
in the detail section to have a white background, 2nd line to be grey, 3rd to
be white etc....

Thanks for any and all help
Ben
 
Here is a past post of mine on this subject which should help:
I know of a couple of ways to do this. I use one or the other
method depending upon the need.

First Way: Full Detail Section colored
(Learned from FredG I think)
Watch out for possible line wrapping here!

1. Code the Detail part of your report like this:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Section(0).BackColor = vbWhite Then
Me.Section(0).BackColor = 15724527
Else
Me.Section(0).BackColor = vbWhite
End If
End Sub

2. Now Code the Page Header part of your report like this
to start a new page with white (I think that's correct).

Private Sub PageHeader_Format(Cancel As Integer, FormatCount As Integer)
Me.Detail.BackColor = 16777215
End Sub

By the way, the color grey I have listed there is a real
light grey. Change to whatever you like.
What this will do is fill the entire detail section with
alternating color. This works fine on some reports, but
for other reports where I have a very small detail section
width-wise it's a little much. So I use a different approach.

Second Way: Small Width Detail section

1. Use the rectangle tool to create a box in your detail
section. Set the following properties for it:
--Name BoxShade
--Visible No
--Back Style Normal
--Back Color 15724527
--Special Effect Flat
--Border Style Transparent

2. Now resize the box to just cover the area of detail you
want to have colored.

3. No go up to to the Format menu and select "Send To
Back". This will put the box behind the other controls in
the Detail section.

4. I usually have an option control on a form that has two
options: "No Shading" and "Shade Every Other Line". I have the
default as No Shading (0 in the option group). I then code
the detail section of the report like this:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Forms]![frmNameOfMyForm]![ShadeOption] = 1 Then
If Me.boxShade.Visible = False Then
Me.boxShade.Visible = True
Else
Me.boxShade.Visible = False
End If
Else
Me.boxShade.Visible = False
End If
End Sub

The shading will now appear on every other row, but just
where I want it to shade. By the way, I still use the
option control on the form for the first example above,
but didn't include the code. You should be able to see how
to code it either with an option control on a form or
without by following the two examples.
And here are some Microsoft KB articles as well:

http://support.microsoft.com/?id=114086

http://support.microsoft.com/?id=210392

http://support.microsoft.com/?id=288154

Hope that gives you some ideas,
--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

in message:
 
Jeff

Thank you very much for you reply. Not only did you answer my question, but
I believe you answered any possible follow ups.

Thanks again!
Ben

Jeff Conrad said:
Here is a past post of mine on this subject which should help:
I know of a couple of ways to do this. I use one or the other
method depending upon the need.

First Way: Full Detail Section colored
(Learned from FredG I think)
Watch out for possible line wrapping here!

1. Code the Detail part of your report like this:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Section(0).BackColor = vbWhite Then
Me.Section(0).BackColor = 15724527
Else
Me.Section(0).BackColor = vbWhite
End If
End Sub

2. Now Code the Page Header part of your report like this
to start a new page with white (I think that's correct).

Private Sub PageHeader_Format(Cancel As Integer, FormatCount As Integer)
Me.Detail.BackColor = 16777215
End Sub

By the way, the color grey I have listed there is a real
light grey. Change to whatever you like.
What this will do is fill the entire detail section with
alternating color. This works fine on some reports, but
for other reports where I have a very small detail section
width-wise it's a little much. So I use a different approach.

Second Way: Small Width Detail section

1. Use the rectangle tool to create a box in your detail
section. Set the following properties for it:
--Name BoxShade
--Visible No
--Back Style Normal
--Back Color 15724527
--Special Effect Flat
--Border Style Transparent

2. Now resize the box to just cover the area of detail you
want to have colored.

3. No go up to to the Format menu and select "Send To
Back". This will put the box behind the other controls in
the Detail section.

4. I usually have an option control on a form that has two
options: "No Shading" and "Shade Every Other Line". I have the
default as No Shading (0 in the option group). I then code
the detail section of the report like this:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Forms]![frmNameOfMyForm]![ShadeOption] = 1 Then
If Me.boxShade.Visible = False Then
Me.boxShade.Visible = True
Else
Me.boxShade.Visible = False
End If
Else
Me.boxShade.Visible = False
End If
End Sub

The shading will now appear on every other row, but just
where I want it to shade. By the way, I still use the
option control on the form for the first example above,
but didn't include the code. You should be able to see how
to code it either with an option control on a form or
without by following the two examples.
And here are some Microsoft KB articles as well:

http://support.microsoft.com/?id=114086

http://support.microsoft.com/?id=210392

http://support.microsoft.com/?id=288154

Hope that gives you some ideas,
--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

in message:
hello,

Is it possible to alternate the colour of the detail section for each line?
I hope that question is clear, if not what im looking for is the first line
in the detail section to have a white background, 2nd line to be grey, 3rd to
be white etc....
 
Is there a way to do this (alternate rows with grey and white backgrounds)
while restricting it to certain groupings???

For Instance:

ID NAME QTY DATE
710 15 3/1/2006 (this line would be grey)
711 20 3/1/2006 }
711 10 4/1/2006 } (these next two lines
white because they
have the same ID
NAME
712 10 3/15/2006 (this line would go to grey)


Jeff Conrad said:
Here is a past post of mine on this subject which should help:
I know of a couple of ways to do this. I use one or the other
method depending upon the need.

First Way: Full Detail Section colored
(Learned from FredG I think)
Watch out for possible line wrapping here!

1. Code the Detail part of your report like this:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Section(0).BackColor = vbWhite Then
Me.Section(0).BackColor = 15724527
Else
Me.Section(0).BackColor = vbWhite
End If
End Sub

2. Now Code the Page Header part of your report like this
to start a new page with white (I think that's correct).

Private Sub PageHeader_Format(Cancel As Integer, FormatCount As Integer)
Me.Detail.BackColor = 16777215
End Sub

By the way, the color grey I have listed there is a real
light grey. Change to whatever you like.
What this will do is fill the entire detail section with
alternating color. This works fine on some reports, but
for other reports where I have a very small detail section
width-wise it's a little much. So I use a different approach.

Second Way: Small Width Detail section

1. Use the rectangle tool to create a box in your detail
section. Set the following properties for it:
--Name BoxShade
--Visible No
--Back Style Normal
--Back Color 15724527
--Special Effect Flat
--Border Style Transparent

2. Now resize the box to just cover the area of detail you
want to have colored.

3. No go up to to the Format menu and select "Send To
Back". This will put the box behind the other controls in
the Detail section.

4. I usually have an option control on a form that has two
options: "No Shading" and "Shade Every Other Line". I have the
default as No Shading (0 in the option group). I then code
the detail section of the report like this:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Forms]![frmNameOfMyForm]![ShadeOption] = 1 Then
If Me.boxShade.Visible = False Then
Me.boxShade.Visible = True
Else
Me.boxShade.Visible = False
End If
Else
Me.boxShade.Visible = False
End If
End Sub

The shading will now appear on every other row, but just
where I want it to shade. By the way, I still use the
option control on the form for the first example above,
but didn't include the code. You should be able to see how
to code it either with an option control on a form or
without by following the two examples.
And here are some Microsoft KB articles as well:

http://support.microsoft.com/?id=114086

http://support.microsoft.com/?id=210392

http://support.microsoft.com/?id=288154

Hope that gives you some ideas,
--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

in message:
hello,

Is it possible to alternate the colour of the detail section for each line?
I hope that question is clear, if not what im looking for is the first line
in the detail section to have a white background, 2nd line to be grey, 3rd to
be white etc....
 
UNTESTED IDEA:

Add a Group by the ID and in the group header's on format set the detail
section's background. You don't need to display the group section - you can
set its height to zero (or its visible property to false)


la knight said:
Is there a way to do this (alternate rows with grey and white backgrounds)
while restricting it to certain groupings???

For Instance:

ID NAME QTY DATE
710 15 3/1/2006 (this line would be grey)
711 20 3/1/2006 }
711 10 4/1/2006 } (these next two lines
white because they
have the same
ID
NAME
712 10 3/15/2006 (this line would go to
grey)


Jeff Conrad said:
Here is a past post of mine on this subject which should help:
I know of a couple of ways to do this. I use one or the other
method depending upon the need.

First Way: Full Detail Section colored
(Learned from FredG I think)
Watch out for possible line wrapping here!

1. Code the Detail part of your report like this:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Section(0).BackColor = vbWhite Then
Me.Section(0).BackColor = 15724527
Else
Me.Section(0).BackColor = vbWhite
End If
End Sub

2. Now Code the Page Header part of your report like this
to start a new page with white (I think that's correct).

Private Sub PageHeader_Format(Cancel As Integer, FormatCount As Integer)
Me.Detail.BackColor = 16777215
End Sub

By the way, the color grey I have listed there is a real
light grey. Change to whatever you like.
What this will do is fill the entire detail section with
alternating color. This works fine on some reports, but
for other reports where I have a very small detail section
width-wise it's a little much. So I use a different approach.

Second Way: Small Width Detail section

1. Use the rectangle tool to create a box in your detail
section. Set the following properties for it:
--Name BoxShade
--Visible No
--Back Style Normal
--Back Color 15724527
--Special Effect Flat
--Border Style Transparent

2. Now resize the box to just cover the area of detail you
want to have colored.

3. No go up to to the Format menu and select "Send To
Back". This will put the box behind the other controls in
the Detail section.

4. I usually have an option control on a form that has two
options: "No Shading" and "Shade Every Other Line". I have the
default as No Shading (0 in the option group). I then code
the detail section of the report like this:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Forms]![frmNameOfMyForm]![ShadeOption] = 1 Then
If Me.boxShade.Visible = False Then
Me.boxShade.Visible = True
Else
Me.boxShade.Visible = False
End If
Else
Me.boxShade.Visible = False
End If
End Sub

The shading will now appear on every other row, but just
where I want it to shade. By the way, I still use the
option control on the form for the first example above,
but didn't include the code. You should be able to see how
to code it either with an option control on a form or
without by following the two examples.
And here are some Microsoft KB articles as well:

http://support.microsoft.com/?id=114086

http://support.microsoft.com/?id=210392

http://support.microsoft.com/?id=288154

Hope that gives you some ideas,
--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

in message:
hello,

Is it possible to alternate the colour of the detail section for each
line?
I hope that question is clear, if not what im looking for is the first
line
in the detail section to have a white background, 2nd line to be grey,
3rd to
be white etc....
 
Yes (as far as i know)

you will need to use a counter and group headings and only increment the
counter on the group heading format...in your case the ID would be a group
heading.

HTH

la knight said:
Is there a way to do this (alternate rows with grey and white backgrounds)
while restricting it to certain groupings???

For Instance:

ID NAME QTY DATE
710 15 3/1/2006 (this line would be grey)
711 20 3/1/2006 }
711 10 4/1/2006 } (these next two lines
white because they
have the same ID
NAME
712 10 3/15/2006 (this line would go to grey)


Jeff Conrad said:
Here is a past post of mine on this subject which should help:
I know of a couple of ways to do this. I use one or the other
method depending upon the need.

First Way: Full Detail Section colored
(Learned from FredG I think)
Watch out for possible line wrapping here!

1. Code the Detail part of your report like this:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.Section(0).BackColor = vbWhite Then
Me.Section(0).BackColor = 15724527
Else
Me.Section(0).BackColor = vbWhite
End If
End Sub

2. Now Code the Page Header part of your report like this
to start a new page with white (I think that's correct).

Private Sub PageHeader_Format(Cancel As Integer, FormatCount As Integer)
Me.Detail.BackColor = 16777215
End Sub

By the way, the color grey I have listed there is a real
light grey. Change to whatever you like.
What this will do is fill the entire detail section with
alternating color. This works fine on some reports, but
for other reports where I have a very small detail section
width-wise it's a little much. So I use a different approach.

Second Way: Small Width Detail section

1. Use the rectangle tool to create a box in your detail
section. Set the following properties for it:
--Name BoxShade
--Visible No
--Back Style Normal
--Back Color 15724527
--Special Effect Flat
--Border Style Transparent

2. Now resize the box to just cover the area of detail you
want to have colored.

3. No go up to to the Format menu and select "Send To
Back". This will put the box behind the other controls in
the Detail section.

4. I usually have an option control on a form that has two
options: "No Shading" and "Shade Every Other Line". I have the
default as No Shading (0 in the option group). I then code
the detail section of the report like this:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Forms]![frmNameOfMyForm]![ShadeOption] = 1 Then
If Me.boxShade.Visible = False Then
Me.boxShade.Visible = True
Else
Me.boxShade.Visible = False
End If
Else
Me.boxShade.Visible = False
End If
End Sub

The shading will now appear on every other row, but just
where I want it to shade. By the way, I still use the
option control on the form for the first example above,
but didn't include the code. You should be able to see how
to code it either with an option control on a form or
without by following the two examples.
And here are some Microsoft KB articles as well:

http://support.microsoft.com/?id=114086

http://support.microsoft.com/?id=210392

http://support.microsoft.com/?id=288154

Hope that gives you some ideas,
--
Jeff Conrad
Access Junkie - MVP
http://home.bendbroadband.com/conradsystems/accessjunkie.html
http://www.access.qbuilt.com/html/articles.html

in message:
hello,

Is it possible to alternate the colour of the detail section for each line?
I hope that question is clear, if not what im looking for is the first line
in the detail section to have a white background, 2nd line to be grey, 3rd to
be white etc....
 
Ben and John: Thanks for your replies - but it still can't get it to work.
Here's how I have my groups and sorting set.

ID NAME QTY DATE
712 10 2/1/2006
715 5 2/1/2006

710 15 3/1/2006

711 20 3/15/2006
711 10 3/15/2006

First it is grouped by Date and sorted in Ascending Order by Date
<then>
Second, it is grouped by ID Name and sorted in Ascending Order by ID Name

I end up with these sections:
Date Header
ID Header
Detail

Maybe I'm putting the code into the wrong sections?? Any suggestions? Which
code goes in which section? Thanks!
 
Ben and John: Thanks for your replies - but it still can't get it to work.
Here's how I have my groups and sorting set.

ID NAME QTY DATE
712 10 2/1/2006
715 5 2/1/2006

710 15 3/1/2006

711 20 3/15/2006
711 10 3/15/2006

First it is grouped by Date and sorted in Ascending Order by Date
<then>
Second, it is grouped by ID Name and sorted in Ascending Order by ID Name

I end up with these sections:
Date Header
ID Header
Detail

Maybe I'm putting the code into the wrong sections?? Any suggestions? Which
code goes in which section? Thanks!
 
la knight

Your code should be in the on format of the ID header, and your conditional
formating for the coloured bar in the detailed section (i assume thats the
approach you are using).

What i would do is for the on format of the ID header i would have the code:
counter = (counter + 1) mod 2
this will keep the value of counter at either a 0 or a 1

the conditional formating of the coloured bar (which acts as the row
highlighting for the detail section) i would change the colour of its fill
when counter = 0 and when counter = 1.

that should help you resolve this issue.

hth.
 
Ben: Thanks very much for your help. I really understand what your telling me
to do but I just can't figure out how to execute the code. I'm good at html
and java but I'm too new to VBA to execute the code your telling me to use.

To get around my inexperience I came up with a slightly different solution.
Instead - I put in ID Header and Footer, grouped by ID and I let the
rule/line I put into the header make the separation that way. Effective, yes
- pretty, not as nice as it would look with alternating grouped rows of color.

I just didn't want you to get frustrated trying to help someone without
knowing the VBA code. But if you wish to continue on the subject it would be
fine with me.
 
Update for Access 2007: in the form detail sections Format tab (properties
window) there is a line to set the background color and the next line sets
the alternate back color.

For once Microsoft added a useful feature! :-)

Kari
 
Update for Access 2007: in the form detail sections Format tab
(properties window) there is a line to set the background color and the
next line sets the alternate back color.

For once Microsoft added a useful feature! :-)

Except that on my Access 2007 install the alternating background colors
(for some reason) default to white, then black, rendering every even line
completely non-readable.
 
If the computer has a "Theme" (what ever that is) running. Colors
picked from the color chart will not necessarily print as expected.
Solution is to 'build' colors from scratch in the RGB format.

Chuck

I run the default XP theme with classic menus and I am not describing how
it prints. This is what it looks like on my screen. Every time I use
2007 and look at a datasheet I have to change the colors to be able to
read the data.
 
Back
Top