Changing Backcolor of report field at run time

  • Thread starter Thread starter Rick In Maine
  • Start date Start date
R

Rick In Maine

have a large report (+/-300 pp) where the field for each item in the
Group Header is shaded grey.

When the report is generated, I would like to be able to
programmatically change the data item field shading to other colors
based on the text value of another field associated with the data in
the header. There are only 8 different values that are associated with
the Group Header data item, so that should not be too difficult,
provided that I can figure out the code to use.

I have tried to use a Select Case statement in the Report's On Format
event with NO success. It looks to me like this should work but I
suspect that the problem is ME (I'm not experienced at all with Case
Select).

If one of you were trying to do such a thing, how would you proceed?

Thanks for the help
 
Here's some code that changes the font, color, etc.

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


'***************************************************************************************
'* PROGRAM : PSI
'* CREATED : 11/21/05
'* COMMENTS : Format the detail section.
'* PARAMETERS: -
'* RETURNS : -
'* CALLED BY :
'* MODIFIED :

'***************************************************************************************

On Error GoTo HandleErr
Const cstrProcName As String = "rptDaily - Detail_Format"

If Me.Title = "Beg Inv" Then
Me.Title.FontBold = False
Me.One.FontBold = False
Me.Two.FontBold = False
Me.Three.FontBold = False
Me.Four.FontBold = False
Me.Five.FontBold = False
Me.Six.FontBold = False
Me.Seven.FontBold = False
Me.One.ForeColor = RGB(255, 0, 150)
Me.Two.ForeColor = RGB(255, 0, 150)
Me.Three.ForeColor = RGB(255, 0, 150)
Me.Four.ForeColor = RGB(255, 0, 150)
Me.Five.ForeColor = RGB(255, 0, 150)
Me.Six.ForeColor = RGB(255, 0, 150)
Me.Seven.ForeColor = RGB(255, 0, 150)
Me.Title.FontSize = 8
Me.One.FontSize = 8
Me.Two.FontSize = 8
Me.Three.FontSize = 8
Me.Four.FontSize = 8
Me.Five.FontSize = 8
Me.Six.FontSize = 8
Me.Seven.FontSize = 8
ElseIf Me.Title = "Prod" Then
Me.One.ForeColor = RGB(0, 0, 255)
Me.Two.ForeColor = RGB(0, 0, 255)
Me.Three.ForeColor = RGB(0, 0, 255)
Me.Four.ForeColor = RGB(0, 0, 255)
Me.Five.ForeColor = RGB(0, 0, 255)
Me.Six.ForeColor = RGB(0, 0, 255)
Me.Seven.ForeColor = RGB(0, 0, 255)
Me.Title.FontBold = True
Me.One.FontBold = True
Me.Two.FontBold = True
Me.Three.FontBold = True
Me.Four.FontBold = True
Me.Five.FontBold = True
Me.Six.FontBold = True
Me.Seven.FontBold = True
Me.Title.FontSize = 9
Me.One.FontSize = 9
Me.Two.FontSize = 9
Me.Three.FontSize = 9
Me.Four.FontSize = 9
Me.Five.FontSize = 9
Me.Six.FontSize = 9
Me.Seven.FontSize = 9
ElseIf Me.Title = "Retail Sales" Then
Me.Title.FontBold = False
Me.One.FontBold = False
Me.Two.FontBold = False
Me.Three.FontBold = False
Me.Four.FontBold = False
Me.Five.FontBold = False
Me.Six.FontBold = False
Me.Seven.FontBold = False
Me.One.ForeColor = RGB(0, 150, 0)
Me.Two.ForeColor = RGB(0, 150, 0)
Me.Three.ForeColor = RGB(0, 150, 0)
Me.Four.ForeColor = RGB(0, 150, 0)
Me.Five.ForeColor = RGB(0, 150, 0)
Me.Six.ForeColor = RGB(0, 150, 0)
Me.Seven.ForeColor = RGB(0, 150, 0)
Me.Title.FontSize = 8
Me.One.FontSize = 8
Me.Two.FontSize = 8
Me.Three.FontSize = 8
Me.Four.FontSize = 8
Me.Five.FontSize = 8
Me.Six.FontSize = 8
Me.Seven.FontSize = 8
ElseIf Me.Title = "Sales Other" Then
Me.Title.FontBold = False
Me.One.FontBold = False
Me.Two.FontBold = False
Me.Three.FontBold = False
Me.Four.FontBold = False
Me.Five.FontBold = False
Me.Six.FontBold = False
Me.Seven.FontBold = False
Me.One.ForeColor = RGB(0, 150, 0)
Me.Two.ForeColor = RGB(0, 150, 0)
Me.Three.ForeColor = RGB(0, 150, 0)
Me.Four.ForeColor = RGB(0, 150, 0)
Me.Five.ForeColor = RGB(0, 150, 0)
Me.Six.ForeColor = RGB(0, 150, 0)
Me.Seven.ForeColor = RGB(0, 150, 0)
Me.Title.FontSize = 8
Me.One.FontSize = 8
Me.Two.FontSize = 8
Me.Three.FontSize = 8
Me.Four.FontSize = 8
Me.Five.FontSize = 8
Me.Six.FontSize = 8
Me.Seven.FontSize = 8
Else
Me.Title.FontBold = False
Me.One.FontBold = False
Me.Two.FontBold = False
Me.Three.FontBold = False
Me.Four.FontBold = False
Me.Five.FontBold = False
Me.Six.FontBold = False
Me.Seven.FontBold = False
Me.One.ForeColor = RGB(50, 50, 50)
Me.Two.ForeColor = RGB(50, 50, 50)
Me.Three.ForeColor = RGB(50, 50, 50)
Me.Four.ForeColor = RGB(50, 50, 50)
Me.Five.ForeColor = RGB(50, 50, 50)
Me.Six.ForeColor = RGB(50, 50, 50)
Me.Seven.ForeColor = RGB(50, 50, 50)
Me.Title.FontSize = 8
Me.One.FontSize = 8
Me.Two.FontSize = 8
Me.Three.FontSize = 8
Me.Four.FontSize = 8
Me.Five.FontSize = 8
Me.Six.FontSize = 8
Me.Seven.FontSize = 8
End If

ExitHere:
Exit Sub

HandleErr:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.DESCRIPTION, vbCritical,
cstrProcName
End Select
GoTo ExitHere

End Sub
 

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

Back
Top