Changing fore and back colour of a combo box

T

Tony Williams

I have a combo box which if the user selects a value I want the forecolor and
backcolor to change. I thought that something like this would do it:
Private Sub Hazards_AfterUpdate()
If IsNot Null([Hazards]) Then
Hazards.BackColor = vbRed
Hazards.ForeColor = vbWhite
End If

End Sub

However there is a problem with the Is Not Null statment as it obviously
isn't correct. Could someone help me with the correct code?
Thanks
Tony
 
T

Tony Williams

Moving forward I found correct is not Null code on Google and realised it
should be Not IsNull and changed the code. However if I select a value in
the combo box in one record now although the colours do change the backcolor
of the combo box changes for all the records. How do I change it for
individual records only when a value is selected?
Here is my code now:
Private Sub Hazards_AfterUpdate()
If IsNull([Hazards]) Then
Hazards.BackColor = vbWhite
Hazards.ForeColor = vbBlack
Else
If Not IsNull([Hazards]) Then
Hazards.BackColor = vbRed
Hazards.ForeColor = vbWhite
End If
End If

End Sub
Thanks
Tony
 
D

Douglas J. Steele

As far as I know, it's not possible to format simply one value in a combo
box.

If it is, Stephen Lebans would have the necessary code on his site
http://www.lebans.com

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Tony Williams said:
Moving forward I found correct is not Null code on Google and realised it
should be Not IsNull and changed the code. However if I select a value in
the combo box in one record now although the colours do change the
backcolor
of the combo box changes for all the records. How do I change it for
individual records only when a value is selected?
Here is my code now:
Private Sub Hazards_AfterUpdate()
If IsNull([Hazards]) Then
Hazards.BackColor = vbWhite
Hazards.ForeColor = vbBlack
Else
If Not IsNull([Hazards]) Then
Hazards.BackColor = vbRed
Hazards.ForeColor = vbWhite
End If
End If

End Sub
Thanks
Tony

Tony Williams said:
I have a combo box which if the user selects a value I want the forecolor
and
backcolor to change. I thought that something like this would do it:
Private Sub Hazards_AfterUpdate()
If IsNot Null([Hazards]) Then
Hazards.BackColor = vbRed
Hazards.ForeColor = vbWhite
End If

End Sub

However there is a problem with the Is Not Null statment as it obviously
isn't correct. Could someone help me with the correct code?
Thanks
Tony
 
T

Tony Williams

Thanks Douglas I had a look and no joy. Also I've noticed that when the form
closes and then reopens the colour change is lost. So back to the drawing
board to find some way of highlighting the fact that the user has chosen a
Hazard for that record only. Maybe I could try making a text box visible with
the word Caution in red or some other such words.
Thanks again
Tony

Douglas J. Steele said:
As far as I know, it's not possible to format simply one value in a combo
box.

If it is, Stephen Lebans would have the necessary code on his site
http://www.lebans.com

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Tony Williams said:
Moving forward I found correct is not Null code on Google and realised it
should be Not IsNull and changed the code. However if I select a value in
the combo box in one record now although the colours do change the
backcolor
of the combo box changes for all the records. How do I change it for
individual records only when a value is selected?
Here is my code now:
Private Sub Hazards_AfterUpdate()
If IsNull([Hazards]) Then
Hazards.BackColor = vbWhite
Hazards.ForeColor = vbBlack
Else
If Not IsNull([Hazards]) Then
Hazards.BackColor = vbRed
Hazards.ForeColor = vbWhite
End If
End If

End Sub
Thanks
Tony

Tony Williams said:
I have a combo box which if the user selects a value I want the forecolor
and
backcolor to change. I thought that something like this would do it:
Private Sub Hazards_AfterUpdate()
If IsNot Null([Hazards]) Then
Hazards.BackColor = vbRed
Hazards.ForeColor = vbWhite
End If

End Sub

However there is a problem with the Is Not Null statment as it obviously
isn't correct. Could someone help me with the correct code?
Thanks
Tony
 

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