How to have a from label appear based on a value in a check box

  • Thread starter Glenn in Los Angeles
  • Start date
G

Glenn in Los Angeles

Any help with how to code a lable in a form so that it only appears when a
check box in a subform is checked?
 
D

Duane Hookom

You can change the label to a text box and set its control source to
something like:
=IIf([checkbox],"Your Caption","")
 
G

Glenn in Los Angeles

That didn't seem to work. It just shows #Name? in the field regardless of
the value in the check box. Here's the language I used

=IIf(
![CheckBox]=-1,"Caption","")

I also tried

=IIf(
![CheckBox]=Yes,"Caption","")

But, in either case, the text box would still be visible all of the time,
and that's what I trying to avoid. Any thoughts?

Duane Hookom said:
You can change the label to a text box and set its control source to
something like:
=IIf([checkbox],"Your Caption","")

--
Duane Hookom
MS Access MVP


Glenn in Los Angeles said:
Any help with how to code a lable in a form so that it only appears when a
check box in a subform is checked?
 
T

tina

the problem is in your syntax, you can't refer to a table like that, within
a form. you need to refer to the checkbox within the subform, via the
subform control. try

=IIf([NameOfSubformControl].[Form]![CheckBox],"Caption","")

and btw, as Duane's expression showed, you don't need to include the "=-1"
in the IIf() function's first argument, because a checkbox's value is
already boolean (true or false).

hth


Glenn in Los Angeles said:
That didn't seem to work. It just shows #Name? in the field regardless of
the value in the check box. Here's the language I used

=IIf(
![CheckBox]=-1,"Caption","")

I also tried

=IIf(
![CheckBox]=Yes,"Caption","")

But, in either case, the text box would still be visible all of the time,
and that's what I trying to avoid. Any thoughts?

Duane Hookom said:
You can change the label to a text box and set its control source to
something like:
=IIf([checkbox],"Your Caption","")

--
Duane Hookom
MS Access MVP


in message news:[email protected]...
Any help with how to code a lable in a form so that it only appears when a
check box in a subform is checked?
 
R

Ron2005

And alternative:

Have the default for the label be NOT visible.

on the check box afterupdate event AND the form OnCurrent event:

me.labelname.visible = me.chkbox


If the chkbox has been checked (true) then the label is visible
otherwise it is not visible
 
T

tina

yes, that alternative will work, but since the label is in the main form,
and the checkbox is in the subform, the correct syntax would be

me.parent.labelname.visible = me.chkbox

hth
 
Top