Combo Box Conditional

  • Thread starter Thread starter Qaspec
  • Start date Start date
Q

Qaspec

I have a bound combo box bound to a table with 5 items.
Worked
Sick
Vacation
Off
Jury

When the combo box is updated on the form i would like
Worked font to become Blue
Sick font to green
Vacation font to purple
Off font to yellow
jury font to red

I've tried to use a conditional format from the menu but i
can only set 3 criteria this way. Is there a way to do
this in VB? or any other suggestions?

Thanks
 
-----Original Message-----
I have a bound combo box bound to a table with 5 items.
Worked
Sick
Vacation
Off
Jury

When the combo box is updated on the form i would like
Worked font to become Blue
Sick font to green
Vacation font to purple
Off font to yellow
jury font to red

I've tried to use a conditional format from the menu but i
can only set 3 criteria this way. Is there a way to do
this in VB? or any other suggestions?

Thanks
.

1. Select your combo box on the form, then create an Event
Procedure in the After Update property for it. Click on
the elipsis beside it to open the VBA Editor.

2. The following code will do what you want:
Private Sub Combo1_AfterUpdate()
If Combo1.Value = "Worked" Then Combo1.ForeColor =
16711680 'Blue
If Combo1.Value = "Sick" Then Combo1.ForeColor =
57600 'Green
If Combo1.Value = "Vacation" Then Combo1.ForeColor =
8388736 'Purple
If Combo1.Value = "Off" Then Combo1.ForeColor =
65535 'Yellow
If Combo1.Value = "Jury" Then Combo1.ForeColor =
255 'Red
End Sub

Tip:
1. The color selected affects the color of all the choices
in the combo list next time. You may wish to display the
selected word in its color in a separate text box near the
combobox so that the combo list is always displayed in
black.
 
Back
Top