If I understand what you want correctly, this is how I did the same thing.
Your mileage may vary.
Private Sub cboColorCode_Enter()
Me.cboColorCode.ForeColor = BLACK
Me.cboColorCode.BackColor = WHITE
End Sub
Private Sub cboColorCode_AfterUpdate()
With Me.cboColorCode
If IsNull(Me("cs_color_code")) Then
Me("cs_color_code") = 0
.Requery
.ForeColor = BLACK
.BackColor = WHITE
Else
.ForeColor = .Column(2)
.BackColor = .Column(3)
End If
End With
End Sub
cboColorCode RowSource:
SELECT color_id, color_name, color_fore, color_back FROM lu_color_code ORDER
BY lu_color_code.color_id;
Table lu_color_code
______________________________
color_id color_name color_fore color_back
0 N/A 0 16777215
1 Black 16777215 0
2 Blue 16777215 16711680
3 Green 65535 32768
4 Orange 0 33023
5 Purple 16744703 8388736
6 Red 16777215 255
7 Yellow 16711680 65535
When the form loads, the code from cboColorCode_AU is called to set the
initial color.
Darryl Kerkeslager
"Dwight" <dw*******@hotmail.com> wrote:
Help !
Have a combo box in accsess, with 6 fields, I want each to show up a
different colour when they ar selected/viewed. I have tried the
following code but seems to have no affect can anyone help? (Combo54,
is the name of my combo box, and the cases being "Software" etc, is
the data entered into this table. The table is called type, and the
column this data is entered is also called type. I also have an auto
number column called Type Number.
Private Sub Combo54_AfterUpdate()
Select Case Me!Combo54
Case "Printer Driver"
Me!Combo54.ForeColor = [Red]
Case "Software"
Me!Combo54.ForeColor = [Black]
Case "Operating/Network System"
Me!Combo54.ForeColor = [Magneta]
Case "General Driver"
Me!Combo54.ForeColor = [Yellow]
Case "Patch/Update/SP"
Me!Combo54.ForeColor = [Green]
Case "Lab Software"
Me!Combo54.ForeColor = [Cyan]
End Select
End Sub