check box makes text box visible

  • Thread starter Thread starter MikeP
  • Start date Start date
M

MikeP

I would like to have a text box's visibility tied in with
a check box. In other words, if the check box is
unchecked the text box field would be grayed out or
invisible. When the check box is check the text box field
is visible. Can I do this to multiple controls?

thanks,

MP
 
Yes, this can be done. Grayed out would be the Enabled property,
Visible/Invisible would be the Visible property.

In the AfterUpdate event of the check box and in the Current event of the
form:

Me.txtMyTextbox.Visible = Me.chkMyCheckbox

or to have them work oposite

Me.txtMyTextbox.Visible = Not Me.chkMyCheckbox

Replace Visible with Enabled if you want grayed out instead of invisible.
The textbox can't have the focus when you do this, so you may need to move
the focus first when you do this in the Current event.
 
-----Original Message-----
Yes, this can be done. Grayed out would be the Enabled property,
Visible/Invisible would be the Visible property.

In the AfterUpdate event of the check box and in the Current event of the
form:

Me.txtMyTextbox.Visible = Me.chkMyCheckbox

or to have them work oposite

Me.txtMyTextbox.Visible = Not Me.chkMyCheckbox

Replace Visible with Enabled if you want grayed out instead of invisible.
The textbox can't have the focus when you do this, so you may need to move
the focus first when you do this in the Current event.

--
Wayne Morgan
MS Access MVP





.

This works like a champ, but when I check the box and
uncheck it and move to another record I get the
error "invalid use of null". When I debug it points me to
the Form Current sub. help?

MP
 
-----Original Message-----
Yes, this can be done. Grayed out would be the Enabled property,
Visible/Invisible would be the Visible property.

In the AfterUpdate event of the check box and in the Current event of the
form:

Me.txtMyTextbox.Visible = Me.chkMyCheckbox

or to have them work oposite

Me.txtMyTextbox.Visible = Not Me.chkMyCheckbox

Replace Visible with Enabled if you want grayed out instead of invisible.
The textbox can't have the focus when you do this, so you may need to move
the focus first when you do this in the Current event.

--
Wayne Morgan
MS Access MVP





.

btw, this is in a subform if that matters.

MP
 
Is the checkbox value stored in a field? I added the Current event so that
if you left the checkbox checked for a record, the form would respond to it
when you went back to that record. If the box is unbound, you could set its
Default Value to False, use Nz in the Current event, or remove the code from
the Current event.

....=Nz(Me.chkMyCheckbox, False)
 
-----Original Message-----
Is the checkbox value stored in a field? I added the Current event so that
if you left the checkbox checked for a record, the form would respond to it
when you went back to that record. If the box is unbound, you could set its
Default Value to False, use Nz in the Current event, or remove the code from
the Current event.

....=Nz(Me.chkMyCheckbox, False)

--
Wayne Morgan
MS Access MVP





.

Yes this is in a bound field.

thanks!

MP
 
It being a subform shouldn't matter since the code is running on that form.
Since this is a bound field, you may want to set the default value of the
field to False or True (your choice) so that you don't get Null values.
 
Back
Top