Add primary key dynamically to a subform within subform from the

C

chanu

Hi,
I have a subform whose primary purpose is to serve as a frame to hold
another two embedded subforms at the same level. the second level
subforms(continuous forms) has no linking fields with the First Level Subform
but has referential integrity with the Main form's recordsource. so, when the
subform loads, the primary key of the Main form is to be supplied to the
Second Level Subforms so that they display records pertaining to that ID.
How can i do this?
I look forward to your help, friends.
 
D

Douglas J. Steele

That's what the LinkMasterFields and LinkChildFields of the subform control
are for.
 
D

Daryl S

Chanu -

If the link is between the main form and the secondary subforms, and there
is nothing on the primary subform, then it sounds like you should get rid of
the primary subform altogether. You say it is just a frame for holding the
two subforms. Do you just need a rectable or outline for that? Then the two
secondary subforms can become primary subforms and you can use the
parent/child links to keep everything in sync.

If you really need the primary subform, can you explain why, and what data
it holds? You would need it to have a recordsource with the same key fields
as the main form, and then you could link the secondary subforms to that.
 
C

chanu

Mr.Daryl,
Thanks for your prompt response. Actually i am creating a wizard to enter
values in the main form(i.e.main table). And the second level subforms
display values for different linking tables having one - to- many relation
with the main form's recordset(i.e. main table) .Here, the Primary level
subforms change in a sequence when the user clicks NEXT button. Each Primary
level subforms hold the two Second Level subforms mentioned above displaying
a few items for two different times(one Level 2 subform for old rates and
another for new rates.) To keep them side by side makes comparison easy.
Another necessity for the Primary Subform is:
the set of Primary subforms in the wizard is actually to enter values. The
second level subforms only display values entered through the Primary
subform.Another Beauty of the Primary subform is it has an option group to
decide whether a new item added in the primary subform should go into both
the Second level subforms or into only one of them. So, according to my plan
the primary level form is a must.
As I am a naive in programming, i would greatly appreciate your suggestion
to make any design changes. But try to give me any idea to continue with the
present design
 
C

chanu

Mr.Douglas,
Thanks a lot for your help. But i don’t know how to access mainform’s
Master field from with in the level2 subform(i.e.Subform within the
subform). Actually My Primary subform has only a few unbound controls which
when the user clicks ADD button would pass their values into Level2 subforms
recordsets(into one or both the recordset depending on the value of an
unbound option group). Actually these recordsets are tables with one-to-many
relation with the main form’s recordset and referential integrity enabled.
While saving these values into the recordset , it should find the main
form’s current record Primary ID and save it as a field if the user first
enters these values. If he opens the form again, these Level2 subforms
display values relating to the Main form’s current record. If it is not
possible to directly link these fields in the form, at least i want to pass
the primaryID of the main form to the where condition of the Level2
subform’s recordset query so that i could get what i want. Could please
spare some more time for me, please
 
D

Douglas J. Steele

Add the field to the first level subform (it can be hidden) and link the
first level subform to the second level subform so that you can then link
the main form to the first level subform.
 
C

chanu

Do you mean to say i should add another unbound field in the primary subform
and copy the value of the primary ID of the current record in the main form.
could you please help me with the code.
Thanks in advance
 
D

Douglas J. Steele

No, fields used in the LinkChildFields and LinkMasterFields properties must
be bound.
 
C

chanu

Then how is it possible to link this invisible field and unbound field with
master fields and child fields. could you please once again read my doubt?
The primary subform simply has unbound controls to pass the values to the
level 2 subforms when the user clicks ADD button. while adding (through the
DAO recordset.This recordset opens the tables in the level-2-subforms and
passes the values in the primary subform) the subforms are to save the data
entered in the primary subform unbound controls along with main form's
primaryID. I need your help for this
 
D

Douglas J. Steele

If your parent form is unbound, then you can't use this approach.

You either need to bind the parent form to a recordset, or else put code in
the Current event of the parent form to set the Filter property of the
subforms. To set the filter, you'd do something like:

Private Sub Form_Current()

Me!sfrm1.Form.Filter = "SomeField = " & Me.txtSomeField
Me!sfrm1.Form.FilterOn = True
Me!sfrm1.Form!sfrm2.Form.Filter = "SomeField = " & Me.txtSomeField
Me!sfrm1.Form!sfrm2.Form.FilterOn = True

End Sub

Note that I didn't test the above. It's possible you may also need to
perform requeries:

Private Sub Form_Current()

Me!sfrm1.Form.Filter = "SomeField = " & Me.txtSomeField
Me!sfrm1.Form.FilterOn = True
Me!sfrm1.Form.Requery
Me!sfrm1.Form!sfrm2.Form.Filter = "SomeField = " & Me.txtSomeField
Me!sfrm1.Form!sfrm2.Form.FilterOn = True
Me!sfrm1.Form!sfrm2.Form.Requery

End Sub
 
C

chanu

thanks a lot Mr. Douglas J. steele. If i get such a help from you, who can
say that i can't do programming (though an infant now).
Once again thanks a lot
 

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