Colour text

peterbowles

Registered User.
Local time
Today, 04:00
Joined
Oct 11, 2002
Messages
163
If a number is a negitive how do you change the font colour to RED

Thanks
 
If Sgn(YourNumber) = -1 Then YourControl.ForeColor = vbRed

If your original colour is Black then you might prefer to use the IIf statement.

YourControl.ForeColor = IIf(Sgn(YourNumber) = -1, vbRed, vbBlack)
 
Set the display format for the control to
£#,##0.00[Black];£#,##0.00[Red], remove the currency symbol if it's just a number
 
Thanks
just got two questions

YourControl.ForeColor = IIf(Sgn(YourNumber) = -1, vbRed,

Is YourControl the txtbox that contains the number
What is YouNumber
 
Sorry, YourNumber was the value you were evaluating so in this case it would be YourControl.

YourControl is the textbox that contains the number.
 
the code does work

But the form the control is on is a sub form I have tried all the EVents but non of them will pick it up

Any ideas

Thanks
 
Can you explain how you do this
£#,##0.00[Black];£#,##0.00[Red],

thanks
 
Copy and paste it verbatim into your textbox's format property.
 

Users who are viewing this thread

Back
Top Bottom