Ms-access – Access 2007 best way to link multiple subforms to main form with tabs

ms-accesssubforms

I have a main form with 10 tabs, each tab with one subform control. Started with all 10 tabs as subforms, main form having only a few additional controls, one of which is primary key. Recordsource for all subforms included this primary key. Displays OK but can't add new record as the record navigation on main form does not permit move to new record and new record button on main form does not work. Tried changing design so that all controls on first tab were part of main form rather than subform. Changed all subform recordsets so that they don't include the PK in the query, but link only through the master/child properties. Now it lets me navigate to new record (although it prompts for a new ID parameter before letting you even try to enter one) but won't let me edit existing records.

So what is the right way to do it? Record navigation on subforms switched on but switched off on main form? PK as part of query on recordsource or not? All subforms or good idea to have first tab as part of main form? Any advice?

Best Answer

The primary key (PK) of the main record should match the foreign keys (FK) of the child records.

 tblCustomer              tblOrder
+----------------+       +----------------+
| PK  CustomerID |1--+   | PK  OrderID    |
+----------------+   |   +----------------+
|                |   +--∞| FK  CustomerID |
+----------------+       |                |
                         +----------------+

The Link Master Fields property of an order-subform-control must be CustomerID (PK in tblCustomer) in this example and the Link Child Fields property CustomerID as well (FK in tblOrder).

Related Topic