Not able to find the subform

  • Thread starter Thread starter janiotjoeawie via AccessMonster.com
  • Start date Start date
J

janiotjoeawie via AccessMonster.com

I have a form called frmRelations on this form I have a subform/subreport.
On the subform/subreport I have a subform called frm_Address. The link
between the 2 forms is oke.
On the subform I have a command button called cmdAddress and on the Mainform
I have a command button called cmdCancel.
If I click on the cmdCancel I want to check wether cmdAddress is enabled or
not.
The problem is my vb code gives me the error that the subform frm_Address is
not found.
I can see that it is open, but can't find it with my code.
Why can't I see the form (and therefor not see the cmdAddress)?

Regards
 
Subforms don't actually get opened as Forms. (In other words, they're not
placed in the Forms collection, so you can't address them the way you would
other forms).

To refer to a control on a subform, you need to use:

Forms!NameOfParentForm!NameOfSubformControlOnParentForm.Form!NameOfControlOnSubform

NameOfParentForm and NameOfControlOnSubform should be obvious, but
NameOfSubformControlOnParentForm may need a little clarification.

If you dragged FormA onto FormB to make FormA be a subform and FormB the
parent form, the name of the subform control on FormB will usually be FormA,
unless there's already a FormA subform control on FormB. If there already is
a subform control named FormA anywhere on FormB, the subform control will be
named Childn (where n is an integer)

If you dragged a subform control from the tool box onto FormB and do not use
the Subform/Subreport Wizard to complete the control, the subform control
will be named Childn. If you do use the wizard, you're given the choice of
what to name the control (it'll default to the name of the form, unless, of
course, a control by that name already exists, in which case it'll append a
number to the form name, like FormA1)
 
Thankx,

It worked fine for me.
An other question (just out of curiosity) does it works the other way around
as well.
From the subform to the main form?
Subforms don't actually get opened as Forms. (In other words, they're not
placed in the Forms collection, so you can't address them the way you would
other forms).

To refer to a control on a subform, you need to use:

Forms!NameOfParentForm!NameOfSubformControlOnParentForm.Form!NameOfControlOnSubform

NameOfParentForm and NameOfControlOnSubform should be obvious, but
NameOfSubformControlOnParentForm may need a little clarification.

If you dragged FormA onto FormB to make FormA be a subform and FormB the
parent form, the name of the subform control on FormB will usually be FormA,
unless there's already a FormA subform control on FormB. If there already is
a subform control named FormA anywhere on FormB, the subform control will be
named Childn (where n is an integer)

If you dragged a subform control from the tool box onto FormB and do not use
the Subform/Subreport Wizard to complete the control, the subform control
will be named Childn. If you do use the wizard, you're given the choice of
what to name the control (it'll default to the name of the form, unless, of
course, a control by that name already exists, in which case it'll append a
number to the form name, like FormA1)
I have a form called frmRelations on this form I have a subform/subreport.
On the subform/subreport I have a subform called frm_Address. The link
[quoted text clipped - 12 lines]
 
You can refer to the Parent property of the subform to reference that form,
so from a subform you'd use

Me.Parent!NameOfControlOnParentForm

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


janiotjoeawie via AccessMonster.com said:
Thankx,

It worked fine for me.
An other question (just out of curiosity) does it works the other way
around
as well.
From the subform to the main form?
Subforms don't actually get opened as Forms. (In other words, they're not
placed in the Forms collection, so you can't address them the way you
would
other forms).

To refer to a control on a subform, you need to use:

Forms!NameOfParentForm!NameOfSubformControlOnParentForm.Form!NameOfControlOnSubform

NameOfParentForm and NameOfControlOnSubform should be obvious, but
NameOfSubformControlOnParentForm may need a little clarification.

If you dragged FormA onto FormB to make FormA be a subform and FormB the
parent form, the name of the subform control on FormB will usually be
FormA,
unless there's already a FormA subform control on FormB. If there already
is
a subform control named FormA anywhere on FormB, the subform control will
be
named Childn (where n is an integer)

If you dragged a subform control from the tool box onto FormB and do not
use
the Subform/Subreport Wizard to complete the control, the subform control
will be named Childn. If you do use the wizard, you're given the choice of
what to name the control (it'll default to the name of the form, unless,
of
course, a control by that name already exists, in which case it'll append
a
number to the form name, like FormA1)
I have a form called frmRelations on this form I have a
subform/subreport.
On the subform/subreport I have a subform called frm_Address. The link
[quoted text clipped - 12 lines]
 
Back
Top