Color code Headers

  • Thread starter Datacruz via AccessMonster.com
  • Start date
D

Datacruz via AccessMonster.com

I have a report that requires headers each with a different color. I have
gone to the property of the text box and can change all Headers to one color.
Is there a way to have every 4th header a different color and then repeat
the cycle?
 
A

Allen Browne

Add a text box to the header, and give it these properties:
Control Source =1
Running Sum Over All
Name txtHeaderCount
Format General Number
Visible No

You can now use:
([txtHeaderCount] -1) Mod 4
which returns 0,1,2,3 repeating, so you can set your color by that value.
 
M

Marshall Barton

Datacruz said:
I have a report that requires headers each with a different color. I have
gone to the property of the text box and can change all Headers to one color.
Is there a way to have every 4th header a different color and then repeat
the cycle?

I wonder which header you want to do this? Assuming it's a
group header, add a (hidden) text box (named txtHdrCount) to
the header section, Set its control source expression to =1
and RunningSum property to Over All.

Then you can use some VBA code in the section's Format (or
Print) event procedure to set the colors:

Select Case txtHdrCount Mod 4
Case 0 'pale blue
Me.[group header name].BackColor = RGB(220,220,255)
Case 1 'pink
Me.[group header name].BackColor = RGB(255,192.192)
Case 1 'pale green
Me.[group header name].BackColor = RGB(220,255,220)
Case 1 'pale yellow
Me.[group header name].BackColor = RGB(255,255,220)
End Select
 
A

Allen Browne

Presumably the last two were Case 2 and Case 3

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Marshall Barton said:
Datacruz said:
I have a report that requires headers each with a different color. I have
gone to the property of the text box and can change all Headers to one
color.
Is there a way to have every 4th header a different color and then repeat
the cycle?

I wonder which header you want to do this? Assuming it's a
group header, add a (hidden) text box (named txtHdrCount) to
the header section, Set its control source expression to =1
and RunningSum property to Over All.

Then you can use some VBA code in the section's Format (or
Print) event procedure to set the colors:

Select Case txtHdrCount Mod 4
Case 0 'pale blue
Me.[group header name].BackColor = RGB(220,220,255)
Case 1 'pink
Me.[group header name].BackColor = RGB(255,192.192)
Case 1 'pale green
Me.[group header name].BackColor = RGB(220,255,220)
Case 1 'pale yellow
Me.[group header name].BackColor = RGB(255,255,220)
End Select
 
D

Datacruz via AccessMonster.com

Sorry for the delay in thanking you for the code it works great!
 

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