473,473 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sub-forms of Sub-forms

I'm creating a data-entry form for 3 tables. There is a one-to-many
relationship between table1 and table2 and a 2nd one-to-many between
table2 and table3. What I would like to do is have the user select
from a combo box on the main form a record from Table1. That would
filter the subform on the main form to just the records from Table2
with the PK from Table1. I've got everything working fine up to this
point, but am a bit confused on where to go next.

I need a mechanism for the user to pick one of the records from Table2,
and be presented with an entry for for all records in Table3 that have
the selected PK from Table2. I've tried putting a 2nd subform on my
main form, but am having trouble getting them to link together.
Something else I tried, is putting a command button on each row of
Table2's subform in continuous forms view to open up a seperate form
for Table3.

Jul 20 '06 #1
3 1445
Try setting the Default view of the 2nd and 3rd subform to datasheet
view.
SY

Jul 21 '06 #2
Greetings,

Here is something I came up with that should do what you are asking:

Do the Link Master/Child thing with the mainform and subform1. Subform1
will need to be in Datasheet view for this trick to work.

The 2nd subform - which will also be placed on the mainform (and also
needs to be in datasheet view) will have its recordsource be based on a
query of the table for that subform (a query for table3). You will use
a parameter in the criteria field of the query for the link field
between table2 and table3. This parameter will be a function that you
will create in the Access Module tab. It is a very simple function.

Create and save a standard module (not a class module). Then create a
Public variable of the type whatever the link field type is between
table2 and table3. If the link field is a number then

Public fieldnameVar As Integer

If it is a text field then

Public fieldnameVar As String

Then function is just this:

Function Param() As Integer (or String)
Param = fieldnameVar
End Function

Save the module

Then in the query for table3 in the criteria for the linkfield just add
the function name

Param()

You need to include the Parentheses here.

In the first subform, go to its design view then go the code module for
that form. Every form code module has 2 dropdown boxes at the top of
the module. In the left dropdown for your subform - select "Form". In
the right dropdown select "Current". This is the Current Event of your
subform. Here is where you set the value of the globar var fieldNameVar

Private Sub Form_Current()
fieldnameVar = Me.yourLinkfield
End Sub

When you select a row in subform1, that triggers the Subform's current
Event. You can then set the value of fieldnameVar to the textfield in
the form. If you open the query that contains the Param() as criteria,
you will see that the query gets filtered by the value from the row you
selected in subform1.

Lastly, in the main form you will have a command button. In the command
button you will requery your 2nd subform and the correspponding rows
will show up.

Private Sub Command14_Click()
Me.Form3.Form.Requery
End Sub

So it is Me. the name of your 2nd subform and follow that by
..Form.Requery

You will now see that rows in the 2nd subform that are related to the
row you selected in the first subform.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 21 '06 #3
Thanks for the answer Rich P. It looks like that'll work so I'll give
it a try.

Rich P wrote:
Greetings,

Here is something I came up with that should do what you are asking:

Do the Link Master/Child thing with the mainform and subform1. Subform1
will need to be in Datasheet view for this trick to work.

The 2nd subform - which will also be placed on the mainform (and also
needs to be in datasheet view) will have its recordsource be based on a
query of the table for that subform (a query for table3). You will use
a parameter in the criteria field of the query for the link field
between table2 and table3. This parameter will be a function that you
will create in the Access Module tab. It is a very simple function.

Create and save a standard module (not a class module). Then create a
Public variable of the type whatever the link field type is between
table2 and table3. If the link field is a number then

Public fieldnameVar As Integer

If it is a text field then

Public fieldnameVar As String

Then function is just this:

Function Param() As Integer (or String)
Param = fieldnameVar
End Function

Save the module

Then in the query for table3 in the criteria for the linkfield just add
the function name

Param()

You need to include the Parentheses here.

In the first subform, go to its design view then go the code module for
that form. Every form code module has 2 dropdown boxes at the top of
the module. In the left dropdown for your subform - select "Form". In
the right dropdown select "Current". This is the Current Event of your
subform. Here is where you set the value of the globar var fieldNameVar

Private Sub Form_Current()
fieldnameVar = Me.yourLinkfield
End Sub

When you select a row in subform1, that triggers the Subform's current
Event. You can then set the value of fieldnameVar to the textfield in
the form. If you open the query that contains the Param() as criteria,
you will see that the query gets filtered by the value from the row you
selected in subform1.

Lastly, in the main form you will have a command button. In the command
button you will requery your 2nd subform and the correspponding rows
will show up.

Private Sub Command14_Click()
Me.Form3.Form.Requery
End Sub

So it is Me. the name of your 2nd subform and follow that by
.Form.Requery

You will now see that rows in the 2nd subform that are related to the
row you selected in the first subform.
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JJMM | last post by:
Hi, I have a form (form1) with a large number of subforms inside it (around 20 subforms), There is the possibility of filtering the data using a pop-up form that create/change a query (all the...
3
by: Evil | last post by:
Hi, i have a problem with a treeview and some subforms in MS Access97. I have a form with a treeview on the left side which lets me navigate thru some projects. Then on the right side, i have...
1
by: M Wells | last post by:
Hi All, I am developing an Access 2003 project application with the back end in SQL Server 2003. I have a master form that tracks projects, and several subforms on it that track various...
2
by: Jack | last post by:
Hi all, I searched the archives and found everyone happy with Stephen's MouseWheel On/Off code except for those with subforms. Stephen's page indicates that he has added code to handle subforms...
0
by: Jack | last post by:
Gday everyone, I'm dearly hoping Stephen Lebans is going to update his masterpeice to stop the mouse wheel scrolling to work on subforms *he has indicated this to me but of course beggers can't...
9
by: Zeeshan Iqbal via AccessMonster.com | last post by:
hi, im trying to design a form with two subforms. subforms no.1 (orders) is connected to the main form by customer ID and i dont know how i can connect another subform (order details)to the first...
5
by: Richard Stanton | last post by:
Hello all My database has a main form linked to table1. It has several subforms on the main form, all linked to table2. Table1 and Table2 are linked by primary/foreign key, no duplicates...
8
by: Zlatko Matić | last post by:
Hello. How can I synchronize subforms content with current record in master form, if both form and subform are based on DAO code ? I assigned DAO recordset to forms by using QueryDef, on Load...
2
by: robert.waters | last post by:
Hello, If I have a form containing a Tab Control with N pages, each page containing a subform, are those subforms loaded into memory when another page has the focus? I have tried iterating...
4
by: Harlequin | last post by:
I have a question concerning the need to trigger events within a "child" subform which is itself enbedded within a master "parent" form and which is accessible via a tab in the parent form. Becuase...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.