I use this code quite often ( I have several reports that change color):
If (IsNull(Me.Text1) = True) Then
Me.Text1.ForeColor = RGB(255, 255, 255) 'white
Me.Text1.BackColor = RGB(244, 120, 126) 'red
Me.Text1.FontWeight = 300
Me.Text1.FontSize = 8
GoTo Exit_Detail_Format
Else
Select Case diff2dates2("d", Date, Me.Text1, False)
Case 61 To 90
Me.Text1.BackColor = RGB(255, 255, 19) 'yellow
Me.Text1.ForeColor = RGB(0, 0, 0) 'black
Me.Text1.FontWeight = 600
Me.Text1.FontSize = 9
Case 31 To 60
Me.Text1.BackColor = RGB(254, 162, 106) 'orange
Me.Text1.ForeColor = RGB(0, 0, 0) 'black
Me.Text1.FontWeight = 600
Me.Text1.FontSize = 9
Case -800 To 30
Me.Text1.BackColor = RGB(244, 120, 126) 'red
Me.Text1.ForeColor = RGB(0, 0, 0) 'black
Me.Text1.FontWeight = 600
Me.Text1.FontSize = 9
Case Else
Me.Text1.BackColor = RGB(255, 255, 255) 'white
Me.Text1.ForeColor = RGB(0, 0, 0) 'black
Me.Text1.FontWeight = 300
Me.Text1.FontSize = 8
End Select
End If
This changes the font (size,color,weight) and textbox(backcolor) of a date
field based on the datein the textbox and the current date. You would add
this under the Detail.OnFormat. You will have to work on editing the error
handling. This particular report pulls data from a crosstab where if there
is no information the field is null, where as if you were just to pull the
data from a record in a table/query, you might have to change the
IsNull()=True to Len()=0. The variations to this type of code are endless.
You can change the timeline to pick a specific date in a record or a specific
date in time, or to change the color based on the numeric value of the month,
day, year, hour and even minute or second. You could even change it to look
for specific data in a string ,ie (left$([text],1) = "*") would look at the
first character in the string to see if is an asterisk.
This diff2dates2 function is from :
http://www.accessmvp.com/DJSteele/Diff2Dates.html
where I modified the code to not add the identifier('days','hours','months')
for the time periods and made it return an integer instead of a variant.