Nested Subforms

CoddFish

Registered User.
Local time
Today, 15:45
Joined
May 26, 2003
Messages
36
Does anybody know how to implement nested subforms? I am clueless... Please let me know if you know of a source that explains this, or if you can explain it to me so that I can actually create the thing.

Thanks.

- CoddFish
 
To create a nested subform you need at least two tables and two forms. The subform is nested inside the main form and the two work together to reflect a many to one relationship.

As an extremely simple example, consider a business that sells packages of peanut butter cookies to customers. Hopefully each customer will, over time, make many orders.

Here's how you can get Access to track this:

Create a table called, say, TblCustomers and include the following fields:

CusID -- AutoNumber; Primary Key.
CusName -- Text
CusStreet -- Text
CusCity -- Text

Create another table called, say, TblOrders and include the following fields:

OrdID -- Autonumber; Primary key
OrdDate -- Date
OrdQty -- Number, Long
CusID -- Number, Long

The CusID field in the Orders table will serve to cross-reference a specific order with a specific customer; it's called a foreign key. There will be many orders in the order table for the same satisfied customer. (I apologize if I'm stating the obvious -- just want to keep the gaps filled.)

Once both tables are done, create a form for each of them. You can do this using the Access Forms Wizard, if you like. Name one form FrmCustomers (attach this one, obviously to TblCustomers) and the other FrmOrders (bound to TblOrders).

After both forms are created, open FrmOrders in Design View and change its Default View property to "Continuous Forms." Set Navigation Buttons to "No." Then save and close.

Open FrmCustomers in Design view and make sure you have some empty space at the bottom of the form. Use the mouse to stretch the borders if need be. Once that's set, use the title bar to drag FrmCustomers -- still open, still in Design View -- off to the left of your screen so that you can also get to the Access system window.

In the Access system window click on FrmOrders (don't open it -- just click on its name) and drag and drop it right onto FrmCustomers.

Now check the Link Master and Link Child properties in FrmOrders: if they are blank, type CusID in both of them.

Click File-Save.

Close all and then re-open FrmCustomers and that's it. Your forms are nested. (Yes, you may have to move things around a bit to see everything properly.)

Test as follows: create a customer record, typing in at least a name. And then pop down into your continuous form (the orders form) and create multiple mock orders, each order automatically cross-referenced and linked to the customer displayed above.

Enter a few different customers and add orders for each of them. After that, when moving between customer records, their orders -- if all's configured correctly -- will follow.

Again, very simple, but hopefully it'll give you a place to start from...

Regards,
Tim
 

Users who are viewing this thread

Back
Top Bottom