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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing font color based on another variable

Status
Not open for further replies.

1no7

Technical User
Jun 20, 2002
5
GB
Does anyone know how I can change the font color in a field based on a value in another field.

I need to use a different colour for each value (5 in total). I've tried using an IF...Then statement but so far i've only managed to change the font colour in the fields to the same colour. It appears to be only picking up the value in the first record of the recordset, rather then reading the code for each record.

Any ideas?


 
If you are using Access 2000 and are in a Form, then use conditional formatting. It is on the menubar under Format and will work on each record in a continuous Form.
 
Hi Ino!!

These are fields I have and the code I use to chnge the color.

Apply your field instead of mine (VacationLeft and SickLeft)
================================
If Me!VacationLeft < 0 Then
Me!VacationLeft.ForeColor = QBColor(12)
Else
Me!VacationLeft.ForeColor = QBColor(0)
End If

If Me!SickLeft < 0 Then
Me!SickLeft.ForeColor = QBColor(12)
Else
Me!SickLeft.ForeColor = QBColor(0)
End If
===========================
Hope this helps!!
 
Thanks zevw

This works fine when the form has a default view property set to single form, however I'm using a tabular form that has a default view of continuous, so the code suggested only manages to change all the relevant fields to the same color. Is there anyway around this?

By the way i'm using Access 97 if that helps at all!
 
1no7!!

The real way is to use conditional formatting which is only in Access 2000, that really works great.

Now I use Access 97 alot.

I was thinking, I am not sure this works:

Try in On Current Event Procedure:

to write the code above. What this does, it only focuses on the active record and &quot;might&quot; only change the color of the current record.

Again I&quot;m not sure this works, I also use the code on a Single Form. But what the heck it is always worth a try.

Enjoy, and let me know if it works;




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top