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!

Text color based on if then statement

Status
Not open for further replies.

dannyocean

Technical User
Jan 26, 2001
136
US
Hello all,

I am needing to be able to set the color of a number based upon if it is greater than or less than another number.

Ex - If 4 is greater than5 , then return 4 in blue, if 4 is less than 5 return 4 in red. so the answer is 4 in red.

I am needing help how to do this.

TIA,

danny
 
I not exactly sure what you mean. Do you have 2 text boxes? Let's assume you do. Are the values for these 2 text boxes coming from a table? Assuming they do, then you would need to insert the following code in the OnCurrent event of the form. You may also want to insert it in the AfterUpdate event of the text boxes. You could also create a function, and call it from the OnCurrent and AfterUpdate events.

If (Text4 > Text5) Then
Text4.ForeColor = 16711680 'Color Blue
Else
Text4.ForeColor = 255 'Color Red
End If
 
Thank you for the suggestion. I am working in a report not a form. I do have two text boxes. How do I make this work for a report?

TIA
 
I am still having trouble getting it to work. There is no onformat event on the report. I am working in Access 97.
My choices are
on open
on close
on activate
on deactivate
on page
on error
on no data

I do apologize, I am just not good at writing code.
TIA
 
How about setting up two separate text boxes for each color... controling their content in code.

Private Sub Report_Activate()

If (Text4 > Text5) Then
txtBlueBox = Text4
txtRedBox = ""
Else
txtBlueBox = ""
txtRedBox = Text4
End If

End Sub

Hope this helps.
 
I believe the on_format event is under the detail properties. It's there somewhere. Maq B-)
<insert witty signature here>
 
Thats it!!

Thank you maq and thanks to everyone else how contributed.


danny
 
One more problem. I got it to work for the first day of the month, but I need it to work for all days of the month. So how do I add the code to get day 2 through 31??

TIA

danny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top