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

Combo box background to change according to selection 1

Status
Not open for further replies.

Livinit

Programmer
Feb 20, 2003
5
US
Hi,
I am working on a project, I would like to have the back
ground color of the combobox to change according to the
selection I make from the list of items in that combo box.
for example: the choices are green cable, yellow cable, red cable, etc.... If I choose green then the background will turn to green, and so on....

Thanks for any help you can give.
Livin it
 
Hi Livinit

Try something like this in the After Update event of your Combo Box (where Combo0 is the name of the Combo Box):

Private Sub Combo0_AfterUpdate()
If Me!Combo0 = "red" Then
Me!Combo0.BackColor = 255
ElseIf Me!Combo0 = "green" Then
Me!Combo0.BackColor = 62580
ElseIf Me!Combo0 = "blue" Then
Me!Combo).BackColor = 16711680
End If
End Sub

HTH

Chris
 
Or...

you could try something like this..


Private Sub Combo0_Change()

Select Case Me.Combo0

Case "Red Cable"

Me.Combo0.BackColor = 255

Case "Green Cable"

Me.Combo0.BackColor = 65280

Case "Yellow Cable"

Me.Combo0.BackColor = 8454143

End Select

End Sub

Private Sub Form_Current()

Select Case Me.Combo0

Case "Red Cable"

Me.Combo0.BackColor = 255

Case "Green Cable"

Me.Combo0.BackColor = 65280

Case "Yellow Cable"

Me.Combo0.BackColor = 8454143

End Select

End Sub

This will automatically update the color when the value is changed and not after the record is saved. Also the On_Current section will change the color as you scroll through the records on the form.

I hope this helps.

BAKEMAN [pimp]
 
Just out of curiosity, what kind of application are you working on that would require such a combo?
 
Bakeman,
I'm doing something wrong, I've got everything in there as you showed in your reply. Hints ? [sadeyes]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top