Looping? or What?

G

Guest

I have a Report that I use for a Catalog system
I've added a Color Tab that will change for each Different PageHeader
However, I can only use 2 colors and switch back and forth.
How can I use a standard Pallet of colors, that I choose, and have it loop
through those colors for each change?

Option Compare Database
Option Explicit

Dim getname
Private shadeNextRow As Boolean

Const shadedColor = 14078404
Const normalColor = 14281974

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

On Error GoTo PageHeader_Format_Error

If Me.Table_of_Contents = getname Then

Else

' Choose a color based on the shadeNextRow value
If shadeNextRow = True Then
Me.Box76.BackColor = shadedColor
Else
Me.Box76.BackColor = normalColor
End If

' Switch the color for the next row
shadeNextRow = Not shadeNextRow

End If

getname = Me.Table_of_Contents


PageHeader_Format_Exit:
Exit Sub

PageHeader_Format_Error:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Detail_Format_Exit


End Sub
 
D

Dirk Goldgar

Ben Adams said:
I have a Report that I use for a Catalog system
I've added a Color Tab that will change for each Different PageHeader
However, I can only use 2 colors and switch back and forth.
How can I use a standard Pallet of colors, that I choose, and have it
loop through those colors for each change?

Option Compare Database
Option Explicit

Dim getname
Private shadeNextRow As Boolean

Const shadedColor = 14078404
Const normalColor = 14281974

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

On Error GoTo PageHeader_Format_Error

If Me.Table_of_Contents = getname Then

Else

' Choose a color based on the shadeNextRow value
If shadeNextRow = True Then
Me.Box76.BackColor = shadedColor
Else
Me.Box76.BackColor = normalColor
End If

' Switch the color for the next row
shadeNextRow = Not shadeNextRow

End If

getname = Me.Table_of_Contents


PageHeader_Format_Exit:
Exit Sub

PageHeader_Format_Error:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Detail_Format_Exit


End Sub

I'm not sure exactly what you have in mind, but you could have a
module-level array of colors that you initialize in the Open event, and
a module-level integer variable used to index into that array. Then,
each time you want to switch colors, you could increment the variable,
and wrap it around to zero if it exceeds the upper bound of the array.
Something like this:

'----- start of example code -----
Option Compare Database
Option Explicit

Dim getname

Dim Palette(4) As Long
Dim CurrentColor As Integer

Private Sub Report_Open(Cancel As Integer)

Palette(0) = 14078404
Palette(1) = 14281974
Palette(2) = ...
Palette(3) = ...
Palette(4) = ...

CurrentColor = 0

End Sub

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

' ... misc unrelated code ...

' Set the box's backcolor to the current color
Me.Box76.BackColor = Palette(CurrentColor)

' Switch the current color to the next color in the palette.
CurrentColor = (CurrentColor + 1) Mod 5

' ... misc unrelated code ...

End Sub
'----- end of example code -----
 

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