K,
The classic order entry scenario is shown in the sample database Northwind
(Help, Sample Databases, Northwind Sample Database). It consists of the
following basic tables:
Clients (One side with Orders)
-----------------------------------------------
ClientID AutoNumber (Primary Key [PK])
ClientName Text
Address
City
State
Phone
....other client attributes
Products
-----------------------
ProductID AutoNumber (PK)
ProductName Text
UnitPrice Currency
....other product attributes
Orders (Many side with Clients, One side with OrderDetails)
----------------------------------------------------------------------
OrderID AutoNumber (PK)
ClientID Integer (Foreign Key [FK] to Clients)
OrderDate Date/Time
....other order attributes such as salesperson, payment method, etc.
OrderDetails
--------------------------
OrderDetailID AutoNumber (PK)
OrderID Integer (FK to Orders)
ProductID Integer (FK to Products)
Qty Integer (or Single if it's possible to buy partial units)
UnitPrice Currency
Discount Single
Note that the only fields duplicated from one table to another are PK-FK
pairs. The Orders table doesn't need the Client address, it needs only the
FK ClientID to give "Access" to all the needed Client fields via a query
linked on the PK-FK combination. There is one exception--the UnitPrice field
is duplicated because the OrderDetails table needs to capture the unit price
stored in Products *at the time of the order*.
Data entry is accomplished through a main form based on Orders and a
continuous subform based on OrderDetails, linked by the OrderID (set in the
LinkMasterFields and LinkChildFields properties of the subform).
A particularly convenient order review screen would show all orders of a
given client, along with all the detail for each order, however, Access
prevents a continuous subform from being embedded on another continuous
subform. One nifty workaround an MVP related to me is the following:
Base the main form on Clients to display a single customer and their
address, phone, main contact, etc. Embed a continuous subform based on
Orders, linked by the ClientID. As you move from one client record to the
next, their Orders detail will display.
Next, create an unbound textbox on the main form, called, e.g., txtOrderID.
Then embed a 2nd subform on the main form based on OrderDetails. This time,
instead of linking to a *field* from the main form recordsource, set the
LinkMasterFields property to the name of the unbound textbox, txtOrderID, and
the LinkChildFields property to OrderID. This link means that the 2nd
subform will display the detail records from whatever order is identified in
the unbound textbox. All that's left is to write the OrderID to the textbox
whenever you change focus from one order to another (using the 1st subform's
OnCurrent event), or change to a different customer (using the main form's
OnCurrent event):
Subform's OnCurrent event:
Me.Parent("txtOrderID") = Me![OrderID]
Main form's OnCurrent event:
Me![txtOrderID] = Me.MySubform.Form![OrderID]
It's a beautiful thing.
Sprinks