Making a subform visible after clicking on checkbox

G

Guest

I have a subform that I want to become visble once a checkbox is clicked.
First and foremost, where should the checkbox be placed? In the subform, or
in the main form? I fogured the latter, but it is not recognizing the
subform. But if I place it in the subform, it is not visible to even check in
the first place!!! (HELP!!)

Second, once it is placed apporpriopriately, is the following code correct?

Checkbox_OnClick()
Subform.Visible = TRUE
End SUb

Thanks

Victoria
 
D

Douglas J Steele

On your main form, you have a control that holds the subform. That control
may or may not be named the same as the form that it contains as a subform
(If you added the subform to the main form by dragging the form onto the
main form, the control should be named the same, unless you've got a caption
for the form being used as a subform, in which case the control will be
named the same as the subform's caption. If, however, you chose the subform
control from the toolbar, added it to the form and then selected which form
to use as the subform, either through the wizard or manually, the control
will be named something like "Child0")

Once you've got the correct name for the control that holds the subform,
what you've got should work, although I'd recommend using the Me keyword to
point out to Access that you're referring to a control on the form. The
check box's OnClick event should work, although I usually tend to use its
AfterUpdate event.

If you want to be able to toggle the subform, you might consider using:

Checkbox_OnClick()
Me.Subform.Visible = Me.Checkbox
End Sub
 
G

Guest

Must be on the main form, if it will be on the sub form and the sub form is
not visible you won't be able to click it, because you won't see it

On the after update event of the check box write

Me.SubFormName.Visible = Me.CheckBoxName

change the name of the sub form and the check box to the names you have
 
S

sebt

You're correct that the checkbox should be on the main form; and

Subform.Visible=True
(or Me.Subform.Visible=True)

is correct.
However, "the subform" is ambiguous, and can refer to two different
things - this trips up a lot of people: there's

a) The subform CONTROL on the main form, which is basically a "window"
with a "link" to another form: this is referred to as Me.[name of the
subform control], and you can make it Visible or invisible.
b) The subFORM itself, which is "in" the subform control. You can
refer to this as Me.[name of the subform control].Form

(a) is what you want to refer to in your code in this case.

cheers


Seb
 
G

Guest

I figured it out - would you believe I didn't ave the _ to indicate a space
in the name of the subform - and that was it!!!
 
G

Guest

Thank you - thank you - got it!!!

Ofer said:
Must be on the main form, if it will be on the sub form and the sub form is
not visible you won't be able to click it, because you won't see it

On the after update event of the check box write

Me.SubFormName.Visible = Me.CheckBoxName

change the name of the sub form and the check box to the names you have
 

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