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

Combo Text Colour Change according to item selected.

Status
Not open for further replies.

mo2783

Programmer
Nov 16, 2003
68
GB
Hello All

I have been trying to solve a problem, I have a combo box with 3 Priority settings (High, Medium, Low) I want to change the colour of the text so if High is selected the text would be red, if Medium is selected then text would be Amber, and if Low was selected then the text would be green.

The combo box is called “txtPriortyRanking” and the bound column is 1 which is either 1 for high, 2 for Medium, 3 for low.

Any ideas how I could achieve this?

Please help

Thanks
 
How about checking the value on Change of the combobox?

Something like (to get you started):
Code:
Private Sub Combo0_Change()
Select Case Combo0.Text

    Case "1"
        Combo0.ForeColor = vbRed
    Case "2"
        Combo0.ForeColor = vbYellow
    Case "3"
        Combo0.ForeColor = vbGreen

End Select

End Sub
I will say that changing the forecolour may not display behaviour exactly as you want (i.e. if you change the forecolour, when you drop down the combo all of the selectable options will be in that colour but you can code around that...).

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
OK, this work to an extent, but still not working properly how would i incorporate this so when the form is opened it automatically shows the apporpriate colour? and make sure that the correct text is colour with correct colours?

any ideas please?

thanks

Mo
 
You could have a look at Conditional Formatting.

Select the combobox, then click Format-->Conditional Formatting. It's pretty intuitive from there.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 

Or, you could try putting HarleyQuinn's code in the form's open or current event.

Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top