Keep Alternate Groups and the Detail sections the same color (1 Viewer)

NauticalGent

Ignore List Poster Boy
Local time
Today, 07:29
Joined
Apr 27, 2015
Messages
6,341
Morning folks, what I am trying to do should be simple: I want ALL the records in the detail section to be the same color as the Group they are in.

I found this code and I thought I was home-free:

Code:
Option Compare Database
Option Explicit
Dim blnalternate As Boolean

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

    If blnalternate Then
        Detail.BackColor = 15263976
        GroupHeader0.BackColor = 15263976
    Else
        Detail.BackColor = 14811135
        GroupHeader0.BackColor = 14811135
    End If

    blnalternate = Not (blnalternate)

End Sub

But when I run the report, there is absolutely no change whatsoever. I even removed the conditional check and simply tried to set the Group backcolor with VBA: GroupHeader0.BackColor = 15263976

But when I ran the report, again, there was no change.

Somebody help me before I break something...
 

MarkK

bit cruncher
Local time
Today, 04:29
Joined
Mar 17, 2004
Messages
8,181
Hey, good evening. I would likely do something like this...
Code:
Private count_ As Integer
Private colors_(0 To 1) As Long

Private Sub Report_Open(Cancel As Integer)
    colors_(0) = 15263976
    colors_(1) = 14811135
End Sub

Private Property Get CurrentColor() As Long
    CurrentColor = colors_(count_ Mod 2)
End Property

Private Sub GroupHeader0_Print(Cancel As Integer, PrintCount As Integer)
    count_ = count_ + 1
End Sub
So in Report_Open we define two colors, and then in GroupHeader0_Print, we increment count_, so every GroupHeader0_Print event effectively toggles CurrentColor.
With that in place, at any moment during the execution of the report, we have a consistent color available that we can use for whatever sections happen to occur...
Code:
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)
    Me.GroupHeader0.BackColor = CurrentColor
End Sub
I have not tested this code, but this is how I would approach the problem. 1) Keep track of the two colors. 2) Count the events that toggle the color, and 3) Test the 'event count' as even or odd, to determine which color is current.
Cheers,
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 07:29
Joined
Apr 27, 2015
Messages
6,341
Hey, good evening. I would likely do something like this...
Code:
Private count_ As Integer
Private colors_(0 To 1) As Long

Private Sub Report_Open(Cancel As Integer)
    colors_(0) = 15263976
    colors_(1) = 14811135
End Sub

Private Property Get CurrentColor() As Long
    CurrentColor = colors_(count_ Mod 2)
End Property

Private Sub GroupHeader0_Print(Cancel As Integer, PrintCount As Integer)
    count_ = count_ + 1
End Sub
So in Report_Open we define two colors, and then in GroupHeader0_Print, we increment count_, so every GroupHeader0_Print event effectively toggles CurrentColor.
With that in place, at any moment during the execution of the report, we have a consistent color available that we can use for whatever sections happen to occur...
Code:
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)
    Me.GroupHeader0.BackColor = CurrentColor
End Sub
I have not tested this code, but this is how I would approach the problem. 1) Keep track of the two colors. 2) Count the events that toggle the color, and 3) Test the 'event count' as even or odd, to determine which color is current.
Cheers,
Thanks MarkK, I'm recovering from an afternoon of yardwork in this God-foresaken heat wave (97f) but I will test this 1st thing tomorrow morning. Appreciate your time...
 

MarkK

bit cruncher
Local time
Today, 04:29
Joined
Mar 17, 2004
Messages
8,181
My code never works the first time. I'll check back tomorrow... : )
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 07:29
Joined
Apr 27, 2015
Messages
6,341
Well MarkK, it didnt work at first, or so I thought. But then I REFUSED to believe that you were capable of doing code that "doesn't work", so I took a step back and thought on it.

Then the light bulb went off and I changed the view from "Report View" (acViewReport) to "Print Preview" (acViewReview) and there it was. I really got to get back to basics on forms and reports if I plan on keeping this job...

Thanks for the nudge!
 

MarkK

bit cruncher
Local time
Today, 04:29
Joined
Mar 17, 2004
Messages
8,181
Glad you got it working!
Cheers,
 

Users who are viewing this thread

Top Bottom