Apply Conditional Format to Label

  • Thread starter Thread starter Scott A
  • Start date Start date
S

Scott A

Hello all -

I've been able to successfully apply conditional formats
to controls on forms and in reports, but haven't quite
figured out how to do the same to a label on one of my
forms and am wondering if this would be possible:

I've got an option group on a form, and would like to
change the colour of the label based on which of the five
options have been selected. When I select the label to
try to apply a conditional format, the selection is greyed
out, so I assume this must be done with code.

Any ideas?

Thanks,

Scott
 
Yes!

I think its something like:

If option1 = true then
label1.BackColor = rgb (255,0,0) 'This is Pure Red
Else
if option2 = True then
Label2.BackColor = rgb (0,255,0) 'This is Pure Green
Else
If option3 = True then
Label3.BackColor = rgb (0,0,255) ' Pure Blue

End If
End If
End If

End Sub


So just mix and match your colours to suit.

HTH

James
 
Scott,

Another option is to change the label to a textbox, with its
controlsource property set to ...
="Whatever text you want"
.... and then you can apply Conditional Formatting to it.

By the way, the syntax of James's suggested code needs a slight tweak.
More like...
If YourOptionGroup = 1 Then
YourLabel.BackColor = rgb (255,0,0) 'This is Pure Red
ElseIf YourOptionGroup = 2 Then
YourLabel.BackColor = rgb (0,255,0) 'This is Pure Green
ElseIf YourOptionGroup = 3 Then
YourLabel.BackColor = rgb (0,0,255) ' Pure Blue
End If

- Steve Schapel, Microsoft Access MVP
 
Back
Top