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

If Then statement to set font color 1

Status
Not open for further replies.

rcreed1

Technical User
May 20, 2004
36
0
0
US
Hello,

I have two text boxes one is named "WARDENS ASSIGNED" and the other "MIN WARDENS NEEDED". I was hoping there was a way that IF WARDENS ASSIGNED < MIN WARDENS NEEDED then forecolor is red else blue?

If there is such a code I would also need to know where to place it. Both of these text boxes already have expressions as their control source.

Any help with this would be greatly appreciated.

Thank you
SFC Reed
 
try this in your form on current event

==========================================
Private Sub Form_Current()
If Me![Text1] > Me![Text2] Or Me![Text1] = Me![Text2] Then
Me![Text1].ForeColor = vbBlue
Else
Me![Text1].ForeColor = vbRed
End If
End Sub
==========================================

this will check if the value of wardens assigned is greater than or equal to the wardens needed value if so it set the font color to blue else it set the font color to red

you will need to replace the Text1 and Text2 in the code with the same names as your combo boxes (wardens assigned and wardens needed) respectively

"My God! It's full of stars...
 
Thank you,

Didn't realize it was that easy.

thanks
 
scottian,
How can I modify the code below, if I want the text to change to the color red when somebody updates that field?


If Me![Text1] > Me![Text2] Or Me![Text1] = Me![Text2] Then
Me![Text1].ForeColor = vbBlue
Else
Me![Text1].ForeColor = vbRed
End If
End Sub


Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
In the LostFocus event procedure of the TextBox named, say Text1, you may add some code like this:
If Me![Text1] = Me![Text1].OldValue Then
Me![Text1].ForeColor = vbBlue
Else
Me![Text1].ForeColor = vbRed
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,
This is a continuous form.

Would this change every record for this field to that color?

If the answer is yes, that is not what I want.

I will try it tomorrow and see what happens.

Thanks so much.

I will let you know what happens.

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
PHV,
When I apply the code, it changes the color of every record in the database, for that particular field, on my continuous form.

Any other ideas?

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top