Option Button label color change

  • Thread starter Dave69 via AccessMonster.com
  • Start date
D

Dave69 via AccessMonster.com

I have an option button on my form named Expired that is tied to an unbound
text field named Judge which uses =DateDiff("d",[ExpDat],Now()) in the
Control Source to toggle on or off.

Expired uses =IIf([Judge]>=0,True,False) to accomplish this and, thus far,
works like a charm. I'm fairly new to code/statements and would like to know
if there is a way to toggle Expired's label (Label48) to change color as well.
 
M

Marshall Barton

Dave69 said:
I have an option button on my form named Expired that is tied to an unbound
text field named Judge which uses =DateDiff("d",[ExpDat],Now()) in the
Control Source to toggle on or off.

Expired uses =IIf([Judge]>=0,True,False) to accomplish this and, thus far,
works like a charm. I'm fairly new to code/statements and would like to know
if there is a way to toggle Expired's label (Label48) to change color as well.


Sure, but you need to use a little code to work with a label
control. Also note that you can not reliably use the value
of a calculated control in a VBA procedure because the code
will probably run before the text box expression is
evaluated. The code could be like:

If DateDiff("d", Me.ExpDat, Now) > 0 Then
Me.Label48.BackColor = RGB(255,255,224) 'pale yellow
Else
Me.Label48.BackColor = <whatever color you have now>
End If

If the form is displayed in continuous or datasheet view,
that will not work the way you want. Another approach that
foes not require any code and will work in any view is to
change the label to a locked text box and use Conditional
Formatting to change the color (no code needed). The CF
expression would just be:
[Judge]
You can not use the CF approach if the different behavior of
a label vs text box is important.
 
D

Dave69 via AccessMonster.com

Marshall:

Apparrently, I can be taught. I plugged your code into the form's On Current
event (a leap of faith on my part--I wasn't entirely sure where to put it)
and nothing happened. Then I changed BackColor to ForeColor, and presto!
works like a charm... Maybe the back style should be Normal and not
transperant for BackColor to work? I'll try that too.

Anyway thank you very much, I can now allow the bruises on my forehead to
heal.

Marshall said:
I have an option button on my form named Expired that is tied to an unbound
text field named Judge which uses =DateDiff("d",[ExpDat],Now()) in the
[quoted text clipped - 3 lines]
works like a charm. I'm fairly new to code/statements and would like to know
if there is a way to toggle Expired's label (Label48) to change color as well.

Sure, but you need to use a little code to work with a label
control. Also note that you can not reliably use the value
of a calculated control in a VBA procedure because the code
will probably run before the text box expression is
evaluated. The code could be like:

If DateDiff("d", Me.ExpDat, Now) > 0 Then
Me.Label48.BackColor = RGB(255,255,224) 'pale yellow
Else
Me.Label48.BackColor = <whatever color you have now>
End If

If the form is displayed in continuous or datasheet view,
that will not work the way you want. Another approach that
foes not require any code and will work in any view is to
change the label to a locked text box and use Conditional
Formatting to change the color (no code needed). The CF
expression would just be:
[Judge]
You can not use the CF approach if the different behavior of
a label vs text box is important.
 
M

Marshall Barton

Dave69 said:
Apparrently, I can be taught. I plugged your code into the form's On Current
event (a leap of faith on my part--I wasn't entirely sure where to put it)
and nothing happened. Then I changed BackColor to ForeColor, and presto!
works like a charm... Maybe the back style should be Normal and not
transperant for BackColor to work? I'll try that too.

Anyway thank you very much, I can now allow the bruises on my forehead to
heal.


:) May I suggest wearing a padded headband?

And, you are right, BackColor is useless when BackStyle is
set to Transparent.

You are also right about using the form's Current event. I
should have said that the code should go in both the Current
event AND in the ExpDat text box's AfterUpdate event.
 
D

Dave69 via AccessMonster.com

Thanks for the info!

Marshall said:
Apparrently, I can be taught. I plugged your code into the form's On Current
event (a leap of faith on my part--I wasn't entirely sure where to put it)
[quoted text clipped - 4 lines]
Anyway thank you very much, I can now allow the bruises on my forehead to
heal.

:) May I suggest wearing a padded headband?

And, you are right, BackColor is useless when BackStyle is
set to Transparent.

You are also right about using the form's Current event. I
should have said that the code should go in both the Current
event AND in the ExpDat text box's AfterUpdate event.
 

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