Nee alternate color in both header and detail (1 Viewer)

smcfadden777

Registered User.
Local time
Today, 12:06
Joined
May 24, 2012
Messages
10
I want the Group Header, and the Detail Section for that header, to be the same color, and for both to alternate for each change in the group header. I am not looking to have each detail record alternate. I need the GH and DS to alternate in sync. Any suggestions? Thank you.
 

AccessMSSQL

Seasoned Programmer-ette
Local time
Today, 09:06
Joined
May 3, 2012
Messages
636
I'm not sure you can do that because once the detail section is rendered, the group header has already formatted. Try setting the alternate back color of your detail section and header section to the same color. This is in the header properties and detail properties of your report.
 

smcfadden777

Registered User.
Local time
Today, 12:06
Joined
May 24, 2012
Messages
10
Re: Need alternate color in both header and detail

Thank you for the quick reply. I have done as you suggested and the results are that the detail records alternate color within the group. This is way to many shading lines and looks very confusing.

My hope is to present each Group and its details as belonging together.
 

smcfadden777

Registered User.
Local time
Today, 12:06
Joined
May 24, 2012
Messages
10
Re: Need alternate color in both header and detail

I think what I am looking for is some code that will paint each detail section the same shade as its group header. And have the group header alternate shade, either by using the properties or code that would preceed the code telling the detail section to be the same as the heder.
 

tpuhlig

Registered User.
Local time
Today, 09:06
Joined
Nov 20, 2009
Messages
15
I would try it this way. Put another field in your query that assigns a odd or even number to you group. It would have to go alone with your sorting.

In your report, since your header and footer would be the same size. strech that field over the whole section of the header. Force it to the back.

Do an conditional formating for even numbers and one for odd numbers on that field. Make sure that you make the font the same color as the background so it won't show up.

Do the same for the footer section.
 

tpuhlig

Registered User.
Local time
Today, 09:06
Joined
Nov 20, 2009
Messages
15
I thought it said footer. You said detail. It still may work. You would just have to have the field in the detail section set to "can grow" and "can shink"
 

AccessMSSQL

Seasoned Programmer-ette
Local time
Today, 09:06
Joined
May 3, 2012
Messages
636
If you want to use VBA code you can try this in your report module?
Code:
Option Compare Database
Option Explicit
Const Color1 As Long = 13568231
Const Color2 As Long = 567772
Public CurrentColor As Long
 
 
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me.Detail.BackColor = CurrentColor
End Sub
 
Private Sub GroupHeader0_Format(Cancel As Integer, FormatCount As Integer)
If CurrentColor = 0 Then
    CurrentColor = Color1
elseIf CurrentColor = Color1 Then
    CurrentColor = Color2
Else
    CurrentColor = Color1
End If
Me.GroupHeader0.BackColor = CurrentColor
End Sub

The numbers I put in for the colors aren't correct. You will need to actually convert the hex color that Access uses to a numeric value when put in the code. I think you can convert these using the rgb function (ex: rgb(255, 0 , 0) which is RED.
 
Last edited:

smcfadden777

Registered User.
Local time
Today, 12:06
Joined
May 24, 2012
Messages
10
Re: Need alternate color in both header and detail

tpuhlig Nice idea but could not get there:
Group and data are generated by a query and don’t see how to add an odd/even field in a way that will assure the data is presented in alpha/numeric order and still have alternating shades. I’m not sure if you can add fields to queries in any manner, just append them. Thank you.

AccessMSSQL Thank you. I will give it a try and let you know.
 

tpuhlig

Registered User.
Local time
Today, 09:06
Joined
Nov 20, 2009
Messages
15
Re: Need alternate color in both header and detail

I know there is a way. I had a sorting issue a while back in a report. I needed put the groups in order on the report as 1,2,3,4. I could not use the sort because some time a group would be missing so it needed to be 1,2,4 (3 mising) but on the report it had to be 1,2,3.

I found the solution on this site. I need to go to a meeting now for a few hours but can look for it later if you still want to try this route.

just let me know.

tpuhlig Nice idea but could not get there:
Group and data are generated by a query and don’t see how to add an odd/even field in a way that will assure the data is presented in alpha/numeric order and still have alternating shades. I’m not sure if you can add fields to queries in any manner, just append them. Thank you.

AccessMSSQL Thank you. I will give it a try and let you know.
 

smcfadden777

Registered User.
Local time
Today, 12:06
Joined
May 24, 2012
Messages
10
AccessMSSQL I tried your code and coud not get it to work. I have attached a screen shot of what I have entered. The report opens in "Report View" but gives a "The expression On Format you entered as the event property setting produces the following error: Ambiguous name detected: Detail_Format." when I try to open it in "Print View". I don't see any ambiguous statements, but I'm not real savvy :eek:.
 

Attachments

  • deb Report Code.jpg
    deb Report Code.jpg
    76.7 KB · Views: 206
  • deb Report Code2.jpg
    deb Report Code2.jpg
    22.4 KB · Views: 166

smcfadden777

Registered User.
Local time
Today, 12:06
Joined
May 24, 2012
Messages
10
I found a solution presented by Allen Browne which is posted in many forums but it does not have the desired results when I try it.

If you want to alternate the color for entire groups (not for each record),
you could do that with a combination of Running Sum and either Conditional
Formatting or Format event:

1. Place a text box in your Group Header, and give it these properties:
Control Source =1
Running Sum Over All
Format General Number
Visible No
Name txtGroupCount

2. Set the On Format event of the Detail section to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.
Set up the routine like this, replacing the vbBlue and vbRed with the RGB
colors you want:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim lngColor As Long

If FormatCount = 1 Then
lngColor = IIf(Me.txtGroupCount Mod 2 = 0, vbBlue, vbRed)
If Me.Section(acDetail).BackColor <> lngColor Then
Me.Section(acDetail).BackColor = lngColor
End If
End If
End Sub


I get aternating colors but they do not alternate in the header and alternate for each on the detail records :eek:.

It seems like somethinng is missing.

Sorry about the smiley faces... I don't get out much.
 

Attachments

  • deb Report Code3.jpg
    deb Report Code3.jpg
    85.9 KB · Views: 244

smcfadden777

Registered User.
Local time
Today, 12:06
Joined
May 24, 2012
Messages
10
Never got the above to work.

I have changed up my report a bit but still have a problem with alternating colors

I am now using a subreport to list the payments, How do I get the backgrund color of the subreport to change colors with the detail section of the main report when it alternates?

Any help would be appreciated.
 

AccessMSSQL

Seasoned Programmer-ette
Local time
Today, 09:06
Joined
May 3, 2012
Messages
636
smcfadden777:
I've been out the past week - did you solve your alternating color issue?
 

Users who are viewing this thread

Top Bottom