Show Label & Text Box in Report based on Checkbox

  • Thread starter Thread starter blobb
  • Start date Start date
B

blobb

Hi. I am attempting to show a label and textbox based on a checkbox in a
report.
The report is based on a SQL query joining two tables. The checkbox field
is included in the query. Currently in the properties, I have the label and
textbox .visible = false. I would like to set the label and textbox to
visible when the checkbox response = Yes.

I tried the OnLoad event of the form

Private Sub Report_Load()
If Checkbox = "Yes" Then
Label.Visible = True
Textbox.Visible = True
End If
End Sub

This didn't work. Could someone help? I am unable to define the event for
the textbox and label directly because this is a report and not a form.

thanks.
 
Instead of using code, just use an expression in a text box.

If the check box is named check1, set the Control Source of a text box to:
=IIf([check1], "it's checked", Null)

To achieve the same for the label, right-click it and Change To | Text Box.
Then set the Control Source to:
=IIf([check1], "whatever the label should say", Null)
 
Allen,

Thank you that worked well for the labels (converted to text boxes) but not
for the field value.

this worked:

=IIF([check1],"my text",Null)

but this did not work:

=IIF([check1],[field1],Null)

also tried this:

=IIF([check1],[table1]![field1],Null)

any suggestions? Thanks again. Much Appreciated.

Allen Browne said:
Instead of using code, just use an expression in a text box.

If the check box is named check1, set the Control Source of a text box to:
=IIf([check1], "it's checked", Null)

To achieve the same for the label, right-click it and Change To | Text Box.
Then set the Control Source to:
=IIf([check1], "whatever the label should say", Null)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


blobb said:
Hi. I am attempting to show a label and textbox based on a checkbox in a
report.
The report is based on a SQL query joining two tables. The checkbox field
is included in the query. Currently in the properties, I have the label
and
textbox .visible = false. I would like to set the label and textbox to
visible when the checkbox response = Yes.

I tried the OnLoad event of the form

Private Sub Report_Load()
If Checkbox = "Yes" Then
Label.Visible = True
Textbox.Visible = True
End If
End Sub

This didn't work. Could someone help? I am unable to define the event
for
the textbox and label directly because this is a report and not a form.

thanks.

.
 
I figured it out and thought that I should post just incase someone else runs
into this. For the text box field (showing the data) I left the control
source equal to my field. With the modifications using the IIF statement in
the label turned text box (referred as label/textbox hereafter) controls on
my report -- the data field appears when the label/textbox controls appear
and does not appear when the label/textbox controls do not.

so:

control source label turned textbox control: =IIF([check1],"My Text",Null)
control source textbox (for the field) control: MyField

Thanks for the help!

blobb said:
Allen,

Thank you that worked well for the labels (converted to text boxes) but not
for the field value.

this worked:

=IIF([check1],"my text",Null)

but this did not work:

=IIF([check1],[field1],Null)

also tried this:

=IIF([check1],[table1]![field1],Null)

any suggestions? Thanks again. Much Appreciated.

Allen Browne said:
Instead of using code, just use an expression in a text box.

If the check box is named check1, set the Control Source of a text box to:
=IIf([check1], "it's checked", Null)

To achieve the same for the label, right-click it and Change To | Text Box.
Then set the Control Source to:
=IIf([check1], "whatever the label should say", Null)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


blobb said:
Hi. I am attempting to show a label and textbox based on a checkbox in a
report.
The report is based on a SQL query joining two tables. The checkbox field
is included in the query. Currently in the properties, I have the label
and
textbox .visible = false. I would like to set the label and textbox to
visible when the checkbox response = Yes.

I tried the OnLoad event of the form

Private Sub Report_Load()
If Checkbox = "Yes" Then
Label.Visible = True
Textbox.Visible = True
End If
End Sub

This didn't work. Could someone help? I am unable to define the event
for
the textbox and label directly because this is a report and not a form.

thanks.

.
 
Back
Top