Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Font Color Based on Criteria 1

Status
Not open for further replies.

gabriellec

Programmer
Mar 20, 2001
19
US
I have a report made which is based on a query. The goal of the report is to show a simple "Yes" or "No" to show if a project was completed on time. Everything works well with the query and report functions.

I would like to make the report clearer. Can anyone tell me how to change the properties so that when the record shows "No" the report shows that whole entry as different colored text?

Thanks
 
--- Begin Code ---
Private Sub Detail_Format()

dim lngRed as long, lngBlack as long

lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)

If txtYesNo.Value = "No" Then
txtYesNo.ForeColor = lngRed
...
Else
txtYesNo.ForeColor = lngBlack
...
end if
end sub
--- End Code ---


The Detail_Format event runs each time a different detail is formatted on the page.

Hope that helps! :) Please let me know if you run into any questions/issues (I didn't test the above code before I typed it in here.. sorry..)
 
Thank you for your help. For some reason... I can get it in and compile it. But when I run the report the function does not trigger. Do I need to place it under "On Open?"

This is what I have so far:
------
Private Sub Detail_format()
Dim IngRed As Long, IngBlack As Long
IngRed = RGB(255, 0, 0)
IngBlack = RGB(0, 0, 0)

If [GoalsMet].Value = "No" Then
[GoalsMet].ForeColor = IngRed

Else
[GoalsMet].ForeColor = IngBlack

End If


----
I also was wondering if it matters that instead of a 0,-1 value, I have text Yes and No for the Goals Met Field?

 
That is a possibility (that the problem is the "Yes"/"No" vs. True/False distinction..) How exactly is the value of [GoalsMet] derived? Is it:
a) based on a formula that returns True or False, and the text box is set to display "Yes" or "No"
b) based on a formula that returns the text, "Yes" or "No"
c) based on a Yes/No field, and the text box is set to display either "Yes" or "No" or
d) based on a text field which has the text "Yes" or "No" in it?

When I wrote the code above, I assumed it was either B or D. If it's either A or C, you'd need to change "Yes" to True (no quotes), and change "No" to False (no quotes).

Another possibility is that it's not linking the Detail_Format subroutine to the Detail_Format event. Access does that sometimes, particularly if you didn't create the subroutine through the property sheet.
Go into the property sheet for the detail section, Events tab, and make sure you see "Event Procedure" in the "Format" line.
If you don't, select Event Procedure from the drop-down, click the "..." thingy, and it should open the code window with the cursor in the Detail_Format subroutine.
If, instead, it opens the code window with a totally different (blank) Detail_Format subroutine, cut and paste all the code from the old one into the new to get it to link the procedure with the event.

Please let me know if you run into anything else, and I'll hope to help :cool:
 
I was reading your question, Did you get this to work? I have a similiar delimma but I am unable to get this to work. I have no experi with writing code.
 
Why not test in the recordset field rather than the textbox:

[tt]

If [ProjectOnTime] then

txtOnTime.backcolor

ELSE

txtOnTime.backcolor

END IF

[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top