Linking 2 Subforms

J

JKarchner

After reading several posts on these forums, I am beginning to think that
what I would like to do is impossible. I don't know if anyone can point me
in the right direction or not, but here goes. I currently have a form with 2
subforms (both in datasheet view). The main form has combo boxes that filter
the results in the first subform. I would like to be able to select a record
in the first subform and have on the related records shown in the second
subform. I believe this has something to do with Parent-Child links, but i
know that you cannot have a parent-child link between 2 subforms. Any help
anyone can provide would be great, Thanks!
 
R

Rick Brandt

JKarchner said:
After reading several posts on these forums, I am beginning to think that
what I would like to do is impossible. I don't know if anyone can point me
in the right direction or not, but here goes. I currently have a form with 2
subforms (both in datasheet view). The main form has combo boxes that filter
the results in the first subform. I would like to be able to select a record
in the first subform and have on the related records shown in the second
subform. I believe this has something to do with Parent-Child links, but i
know that you cannot have a parent-child link between 2 subforms. Any help
anyone can provide would be great, Thanks!

The ChildLink property must list one or more *fields* found in the underlying
form's Recordsource. However; the MasterLink property can contain any valid
expression. That expression can refer to controls (bound or unbound) on the
parent form and since the other subform IS a control on the parent form, the
expression can refer to that as well. So for example a MasterLink property
could look like...

OtherSubformControlName.Form!FieldOnOtherSubform
 
J

JKarchner

Thanks for the quick reply. I tried to enter your suggestion in to the Link
Master Fields section on the second form: frmQuestions.Form!QuestionID. I
then entered this code in the Link Child Fields: frmAnswers.Form!QuestionID.
But then i dont get any results in the second form. So the first form is
frmQuestions and then my second form is frmAnswers, and my second form should
be based on the selection in my first form.

Again thank you very much for your help and quick response!
 
R

Rick Brandt

JKarchner said:
Thanks for the quick reply. I tried to enter your suggestion in to
the Link Master Fields section on the second form:
frmQuestions.Form!QuestionID. I then entered this code in the Link
Child Fields: frmAnswers.Form!QuestionID. But then i dont get any
results in the second form. So the first form is frmQuestions and
then my second form is frmAnswers, and my second form should be based
on the selection in my first form.

Again thank you very much for your help and quick response!

The ChildLink property should JUST be the name of a field in the subform. Just
as it would be in a normal subform being linked to the parent. The only thing
that is different is the MasterLink property.

In your case the properties for the second subform should be...

MasterLink: frmQuestions.Form!QuestionID
ChildLink: QuestionID
 
J

JKarchner

Thanks a million Rick! It works like a charm.

Rick Brandt said:
The ChildLink property should JUST be the name of a field in the subform. Just
as it would be in a normal subform being linked to the parent. The only thing
that is different is the MasterLink property.

In your case the properties for the second subform should be...

MasterLink: frmQuestions.Form!QuestionID
ChildLink: QuestionID
 
A

Albert D. Kallal

JKarchner said:
Thanks for the quick reply. I tried to enter your suggestion in to the
Link
Master Fields section on the second form: frmQuestions.Form!QuestionID. I
then entered this code in the Link Child Fields:
frmAnswers.Form!QuestionID.
But then i dont get any results in the second form. So the first form is
frmQuestions and then my second form is frmAnswers, and my second form
should
be based on the selection in my first form.

Again thank you very much for your help and quick response!

Since you have two sub-forms, the "2nd" sub form will (does not) not see the
first sub-form change.

I suggest you place a

me.Parent.Child2.Requery

In the 1st sub-forms on-current event

Note that that the link setup for the 2nd sub form will be:
:

linkChildFields main_id (whatever is the name of the field in
this sub-form that is used to relate back to the parent table)
LinkMasterFields [MasterForm].[form].[ID] <-- this is also going to be
a sub-form ref,
try either:

LinkMasterFields forms!NameOfMainForm.Form.[1stSubFormName].[form].[ID]
<-- this is also going to be a sub-form ref,

You might be also to also use:

LinkMasterFields me.Parent.Form.[1stSubFormName].[form].[ID] <-- this
is also going to be a sub-form ref,
 

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