Changing font colors based on a field value

J

Joseph Greenberg

I am programming in Access 2007 but it has to be compatible with Access
2003. I have a master report that has a field called txtTribe. There are two
subreports on this report as well (and two lines, and a memo field). The
report is grouped on txtTribe.

I have the following code in the Report_Load and Report_Page events:

txtFamilyName.ForeColor = RGB(0, 0, 0)
txtTribe.ForeColor = RGB(0, 0, 0)

If txtTribe = "AAA" Then
txtFamilyName.ForeColor = RGB(0, 0, 175)
txtTribe.ForeColor = RGB(0, 0, 175)
End If
If txtTribe = "BBB" Then
txtFamilyName.ForeColor = RGB(0, 125, 0)
txtTribe.ForeColor = RGB(0, 125, 0)
End If

The problem I'm having is that the first page does not get the color
treatment it is supposed to (AAA is the first group). How can I keep the
text black in design mode, and ensure the first page gets the correct
coloring? Just as a note, the group CCC is supposed to be black (there are
only 3 groups) - that's why I have the code at the top to reset everything
to black.

Also, how can I iterate through all the fields and controls on the report
(including the subreports) and make sure that they all get the same color
treatment (the code above changes only 2 fields, I want ALL fields
colorized)?

Thank you.
 
D

Duane Hookom

I'm not sure what is where in your report but generally you want to change
properties of controls in code in the On Format event of the section
containing the control.

I can't imagine attempting to use code like this in either the Report Load
or Page events.
 
J

Joseph Greenberg

Ok, that helped! Thank you! But, why can't you imagine this? What is "wrong"
with this?
 
D

Duane Hookom

The only reason I have placed code in the On Page event is never related to
data since data and page are not necessarily directly related. My On Page
event code has draw lines on pages using the Line method.

I don't think there is an On Load event for reports in Access 2003 or earlier.
 

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

Top