Changing Back Color based off value

gmatriix

Registered User.
Local time
Today, 17:20
Joined
Mar 19, 2007
Messages
365
Hello All,

I have this code below that work (sort of). I'm not sure what event to put it on. I tried different ones and it doesn't seem to update when I scroll through the records. If there is a better way to do this then please let me know.

Code:
Dim lngRed As Long
Dim lngGreen As Long
Dim lngYellow As Long

lngGreen = RGB(124, 252, 0)
lngYellow = RGB(255, 215, 0)
lngRed = RGB(255, 0, 0)

If Me.List96 = 3 Then Me.Detail.BackColor = lngRed
If Me.List96 = 2 Then Me.Detail.BackColor = lngYellow
If Me.List96 = 1 Then Me.Detail.BackColor = lngGreen
End Sub

Thanks
 
I though about that but how do I get that to change the back color of the form and not just the text box?
 
What is the Default View of the form, i.e. Continuous Form, Datasheet or Single Form?
 
By the way, did you write the code yourself?

Put it in the Current event of your form and After Update event of the Listbox. Amended:
Code:
Dim lngGreen As Long
Dim lngYellow As Long

lngGreen = RGB(124, 252, 0)
lngYellow = RGB(255, 215, 0)

If Me.List96 = 3 Then 
    Me.Detail.BackColor = vbRed
ElseIf Me.List96 = 2 Then 
    Me.Detail.BackColor = lngYellow
ElseIf Me.List96 = 1 Then 
    Me.Detail.BackColor = lngGreen
Else
    Me.Detail.BackColor = vbBlack
End If
... you need a default colour so I've added vbBlack.
 
Yes I wrote the code myself....forgive me ....im a beginner....thanks I will try...
I will let you know if I have any problems

Thanks
 
It works....just how do I get it to trigger soon as the value in the list box changes

for instance..

Im on record 1 and the listbox says "2" so it turns it yellow
I move to record 2 and it says "3".....the back color show automatically turn red....its working but alittle late.....Any Ideas?
 
Well, if it's working that's as fast as it will get. You can try Conditional Formatting to see if it's faster. Use a textbox as the background of your Detail section.
 

Users who are viewing this thread

Back
Top Bottom