Set Multiple Label Background Colours from Yes/No fields (1 Viewer)

Gigitty

Member
Local time
Today, 09:04
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

  • Doc1.pdf
    232 KB · Views: 367

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:04
Joined
May 7, 2009
Messages
19,237
it will "paint" every record if your form is Continuous form.
you may need to Move your code on the Detail's Paint event.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:04
Joined
May 7, 2009
Messages
19,237
if the "Label" is associated with the checkbox, you can use this
technique (Paint event of Detail section).
 

Attachments

  • checkboxdb.accdb
    508 KB · Views: 321

Gigitty

Member
Local time
Today, 09:04
Joined
Mar 29, 2007
Messages
52
Thanks for your reply Arnel.

I get the following error:-
 

Attachments

  • error.pdf
    61.1 KB · Views: 356

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:04
Joined
May 7, 2009
Messages
19,237
its BackColor not BackColour.
 

Gigitty

Member
Local time
Today, 09:04
Joined
Mar 29, 2007
Messages
52
Aha, being down under that 'US' spelling catches me all the time. No error now but code not working i.e. nothing is happening..
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:04
Joined
May 7, 2009
Messages
19,237
is your form Continuous Form?
if continuous form put the code on Detail section Paint event.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:04
Joined
May 7, 2009
Messages
19,237
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

  • checkboxdb.accdb
    784 KB · Views: 375

Gigitty

Member
Local time
Today, 09:04
Joined
Mar 29, 2007
Messages
52
Fixed!! Damn label property was 'Transparent' and not 'Normal'. Thanks so much Arnel (y)
 

Gigitty

Member
Local time
Today, 09:04
Joined
Mar 29, 2007
Messages
52
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

  • Error2.pdf
    257 KB · Views: 344

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:04
Joined
May 7, 2009
Messages
19,237
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).
 

Gigitty

Member
Local time
Today, 09:04
Joined
Mar 29, 2007
Messages
52
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

Top Bottom