Colors in sections

  • Thread starter Thread starter rob p
  • Start date Start date
R

rob p

Is it possible to format a report so the different sections are different
colors in preview mode but no color in print mode? I am using a HP laser and
the colors show up as shading in the print copy.
 
Rob,
The Report's Activate event only fires when the report is Previewed.
You can take advantage of that and add some code to the report
to change the section backcolor if the report is previewed.

Here is all the coding you will need.

Option Compare Database
Option Explicit
Dim intPreview As Integer
=====
Private Sub Report_Activate()
intPreview = -1
End Sub
=====

Sub Detail_Format(Cancel As Integer, PrintCount As Integer)
If intPreview < 0 Then
Me.Section(0).BackColor = vbYellow
Else
Me.Section(0).BackColor = vbWhite
End If

End Sub
=====

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
If intPreview = -1 Then
Me.Section(1).BackColor = vbBlue
Else
Me.Section(1).BackColor = vbWhite
End If

intPreview = intPreview + 1

End Sub
==========
Add the same code as is in the *** Detail Format event *** to any other
section format event you have in your report.
Change the colors as wanted.
Remember to change the section() number to the correct section as needed:
Section(0) Detail Section
Section(1) Report Header
Section(2) Report Footer
Section(3) Page Header
Section(4) Page Footer
Section(5) First Group Header
etc.
 
Thanks Fred.

Fredg said:
Rob,
The Report's Activate event only fires when the report is Previewed.
You can take advantage of that and add some code to the report
to change the section backcolor if the report is previewed.

Here is all the coding you will need.

Option Compare Database
Option Explicit
Dim intPreview As Integer
=====
Private Sub Report_Activate()
intPreview = -1
End Sub
=====

Sub Detail_Format(Cancel As Integer, PrintCount As Integer)
If intPreview < 0 Then
Me.Section(0).BackColor = vbYellow
Else
Me.Section(0).BackColor = vbWhite
End If

End Sub
=====

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
If intPreview = -1 Then
Me.Section(1).BackColor = vbBlue
Else
Me.Section(1).BackColor = vbWhite
End If

intPreview = intPreview + 1

End Sub
==========
Add the same code as is in the *** Detail Format event *** to any other
section format event you have in your report.
Change the colors as wanted.
Remember to change the section() number to the correct section as needed:
Section(0) Detail Section
Section(1) Report Header
Section(2) Report Footer
Section(3) Page Header
Section(4) Page Footer
Section(5) First Group Header
etc.


--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.
 
Rob,
You may have caught it already, but the code for the detail section should
have read:
<1, not <0

If intPreview < 1 Then
Me.Section(0).BackColor = vbYellow
Else
Me.Section(0).BackColor = vbWhite
End If
 
Back
Top