change background color (1 Viewer)

robertbwainwright

Registered User.
Local time
Yesterday, 18:22
Joined
May 2, 2012
Messages
62
I've created a report, and I am trying to change the background color to red based on the value of a textbox being 0 and it just is not working. I'm thinking I'm using the wrong event.... Here is my code:

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If RndQOH = 0 Then
    Detail.BackColor = vbRed
End If
    
End Sub

thanks for any help in advance!

Robert
 

Minty

AWF VIP
Local time
Today, 00:22
Joined
Jul 26, 2013
Messages
10,372
Try using conditional formatting instead - it works on reports as well as forms.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 00:22
Joined
Feb 19, 2013
Messages
16,657
the format event does not run in Report Preview, only Print Preview

don't know what you are trying to achieve but you may also need to take into account the alternate backcolor and use the retreat action to reset everything or perhaps an else to put color back

If RndQOH = 0 Then
Detail.BackColor = vbRed
Else
Detail.BackColor = vbWhite
End If

meant to say - if you want it to work in the report preview, use the paint event (which does not work for print preview)
 

robertbwainwright

Registered User.
Local time
Yesterday, 18:22
Joined
May 2, 2012
Messages
62
actually I'm trying to change several things from line to line. I used this as an example so not to complicate things, hence I can not use conditional formatting..... Thanks for the replies.
 

Minty

AWF VIP
Local time
Today, 00:22
Joined
Jul 26, 2013
Messages
10,372
You can use conditional formatting- in fact it's possibly the only way you can make line by line colour changes.

It can be made to work on each field separately, rather than a whole section.
 

HiTechCoach

Well-known member
Local time
Yesterday, 18:22
Joined
Mar 6, 2006
Messages
4,357
I've created a report, and I am trying to change the background color to red based on the value of a textbox being 0 and it just is not working. I'm thinking I'm using the wrong event.... Here is my code:

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If RndQOH = 0 Then
    Detail.BackColor = vbRed
End If
    
End Sub

thanks for any help in advance!

Robert

Robert,

Make sure you are in Print Preview mode.
 

Users who are viewing this thread

Top Bottom