Changing a control on a subform?

G

Gary Hull

I am trying to turn some controls in a subform on or off by
using a check box on the main form, can’t get it to work

Here is the code on the check box click event

Private Sub ckShowAWIPrice_Click()
If Me.ckShowAWIPrice = -1 Then
Me!frmDataSubform.Form!txtStandardBond.Visible = True
Me!frmDataSubform.Form!txtStandardNet.Visible = False
End If

End Sub
 
T

tina

i'm guessing that "frmDataSubform" is the name of the form (that you're
using as a subform) as it shows in the database window. is it also the name
of the *subform control within the main form*? your expression has to refer
to the subform control name, not the form object name (sometimes they're the
same, sometimes different, usually depending on how the subform was added to
the main form).

for example, let's say the name of the form object (in the database window)
is frmDataSubform. when you open the main form in Design view and click on
the subform control, and look at the Name, property, you see that the
control is named Child1. so the reference in the code would be

Me!Child1.Form!txtStandardBond

to address another issue, your post stated you want to turn those two
controls "on" AND "off". the code you posted will only turn them on, not
off. suggest you try

Me!Child1.Form!txtStandardBond.Visible = Me!ckShowAWIPrice

replace Child1 with the correct name of the *subform control*, of course. if
the checkbox value is True, the Visible property will be True, and vice
versa. depending on how you're using the main form, you may need to also
include the code in the form's Current event procedure, so the controls will
be appropriately visible or not as you move through existing records.

hth
 

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

Similar Threads


Top