Formatting Combo Box

M

Markus

I have the following code to one of my combo boxes

Private Sub QC10600_AfterUpdate()
If QC10600.Value = "EV" Then QC10600.BackColor = 16711680
If QC10600.Value = "SI" Then QC10600.BackColor = 57600
If QC10600.Value = "VA" Then QC10600.BackColor = 8388736
If QC10600.Value = "OF" Then QC10600.BackColor = 65535
End Sub


This probably has a simple answer. How do I also add in
the criteria that I also want the forecolor to be white if
the backcolor is green, blue, or purple? EV=Blue SI Green
VA= Purple OF = Yellow
Also if I have 6 combo boxes on the form is there a way to
apply a single code to combo boxes QC10600 to QC11100 or
do I have to create this code for every combo box? Any
help is appreciated. Thanks
 
A

Allen Browne

If may be more efficient to do this with conditional formatting (Format
menu), but if you want to do it with code, try something like this:

Private Sub QC10600_AfterUpdate()
With Me.QC100600
Select Case .Value
Case "EV"
.BackColor = 16711680
.ForeColor = vbGreen
Case "SI"
.BackColor = ...

End Select
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top