Dynamic Text Coloring (1 Viewer)

Kinger43

racecar driver
Local time
Yesterday, 20:19
Joined
Aug 17, 2007
Messages
226
I want to dynamically color the text(Forecolor) of a text box in the detail section based on its value. Right now This is what I have
Code:
Private Sub Report_Open(Cancel As Integer)
    If Counter > 10 Then
        DoCmd.SetProperty "OperationCount", acPropertyForeColor, "#ED1C24"
    Else
        DoCmd.SetProperty "OperationCount", acPropertyForeColor, "#000000"
    End If
            
End Sub
Where Counter is an invisible text box that holds the same value as the box I'm trying to color. It just simply isn't working. No errors being thrown, just isn't working. Any help is appreciated, Thanks.
 

boblarson

Smeghead
Local time
Yesterday, 17:19
Joined
Jan 12, 2001
Messages
32,059
You can't do it in the Report's On Open event. It needs to go into the ON FORMAT event of the section where the text box resides. So if it is in the DETAIL section then it goes in the ON FORMAT event of the DETAIL section.
 

boblarson

Smeghead
Local time
Yesterday, 17:19
Joined
Jan 12, 2001
Messages
32,059
Oh, and I forgot to include - if you are on Access 2007 or above then you would need to include the same code on the ON PAINT event if you want it to work in the Report View. If you do, then I would put a new procedure in the report's module and then call that one procedure from both the On Format and On Paint events.
 

Kinger43

racecar driver
Local time
Yesterday, 20:19
Joined
Aug 17, 2007
Messages
226
Thanks Bob!
To complete the thread, here is the code that worked. I did have to put it in the ON FORMAT of the DETAIL section but it also didn't like the "#ED1C24" being used.
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If OperationCount > 10 Then
        DoCmd.SetProperty "OperationCount", acPropertyForeColor, RGB(255, 0, 0)
    Else
        DoCmd.SetProperty "OperationCount", acPropertyForeColor, RGB(0, 0, 0)
    End If
End Sub
I am using Access 2007. I put this code in the ON PAINT event as well even though this report will probably only ever be viewed in Print Preview.
 

vbaInet

AWF VIP
Local time
Today, 01:19
Joined
Jan 22, 2010
Messages
26,374
By the way, based on your last code you can do this using Conditional Formatting instead.
 

Users who are viewing this thread

Top Bottom