Set Multiple Label Background Colours from Yes/No fields

Gigitty

Member
Local time
Today, 11:02
Joined
Mar 29, 2007
Messages
52
Hi all.

I have a bunch of yes/no fields on a form and I would like to set the background colour of the associated label when the field value is true. The code i've tried on the first label isn't working properly in that it is setting the background colour for every record not just the record with 'true' values. Total novice at VBA so any help would be appreciated. Have attached a screen shot.

many thanks in advance.
 

Attachments

it will "paint" every record if your form is Continuous form.
you may need to Move your code on the Detail's Paint event.
 
if the "Label" is associated with the checkbox, you can use this
technique (Paint event of Detail section).
 

Attachments

Thanks for your reply Arnel.

I get the following error:-
 

Attachments

its BackColor not BackColour.
 
Aha, being down under that 'US' spelling catches me all the time. No error now but code not working i.e. nothing is happening..
 
is your form Continuous Form?
if continuous form put the code on Detail section Paint event.
 
Last edited:
go to design view of your form and make sure
the Labels (associated with checkboxes), the Back Style (property->format)
is set as Normal.

see Table2 form.
see also the Click event of each checkbox in design view.
see the Current event of the form.
 

Attachments

Fixed!! Damn label property was 'Transparent' and not 'Normal'. Thanks so much Arnel (y)
 
So i've added in more of the fields to be updated but only the first field that is 'True' is being updated. Clearly if missed something :-(
 

Attachments

why do you have So Many If and Else..End If?
this is how to do it:

Code:
If Me!checkbox1 Then
    Me!checbox1.Controls(0).BackColor = vbGreen
Else
    Me!checbox1.Controls(0).BackColor = vbWhite
End If

If Me!checkbox2 Then
    Me!checbox2.Controls(0).BackColor = vbGreen
Else
    Me!checbox2.Controls(0).BackColor = vbWhite
End If

did you see my code, on how to do it on
Multiple Checkbox control?
And where is this code? again see my example.
Don't force it to work on Load event (this event is only called Once).
 
I did have the code in the 'On Current' event. I've moved my 'End If' comments as you have illustrated. For some reason I though if you had multiple 'If' statements you placed all the 'End If's' at the end. My bad. Thanks again Arnel.
 

Users who are viewing this thread

Back
Top Bottom