Firstly I would agree that a LoadDetails table is unnecessary. You can still
see the products per load if you wish (see below). You do need a Loads table
of course with columns for the attributes of each load, LoadID (the primary
key), LoadDate etc.
As regards data entry you have a number of options, again depending on your
business model, though the options are not mutually exclusive, so you can
have several and use them in conjunction. You could have a Loads table with
a LoadDetails subform linked to the parent form on LoadID. The subform would
have combo boxes bound to the OrderID and ProductID fields and a text box
bound to the Quantity field. This would enable you to build up a load from
various orders or you could just use the form for viewing a load built up per
Order as below..
To 'break down' and order into loads I'd envisage an Orders form with an
OrderDetails subform in the usual way (the sample Northwind databases
provides model for this). You could either have an OrderLoadDetails subform
in the OrderDetails subform, but this would mean the OrderDetails subform
would have to be in single form view.
Alternatively, and this would probably be my choice, would be to have a
correlated subform in the parent Orders form. The way to achieve this is to
a text box somewhere in the Orders form and make its ControlSource property a
reference to the ProductID control on the subform. That control would
normally be a combo box so the ControlSource of the text box in the parent
form would be something like this:
=[OrderDetailsSubformControl].Form![cboProductID]
Note that OrderDetailsSubformControl here is the name of the subform control
in the Orders form, i.e. the control which contains the subform. Set the
Visible property of this text box to False (No in the properties sheet) and
call it something like txtProductIDHidden.
To link the subform based on the OrderDetailLoads table you want the
LinkMasterFields property to be a combination of OrderID and ProductID, so in
the subform control's properties sheet eneter the following as the
LinkMasterFields property:
OrderID; txtProductIDHidden
Do this directly in the properties sheet not via the dialogue which pops up
when you click this property's 'build' button (the one to the right with 3
dots). For the LinkChildFields Property use the field names in the usual
way, so in the properties sheet enter:
OrderID;ProductID
The way this should work is, having entered the order details into the first
subform you can enter one or more rows per product for the current order into
the second subform by selecting the product row in the first subform, i.e.
you can assign product in the order to one or more loads. You can build in
validation into this subform to ensure that you don't ship more than the
total quantity for each product. I'd suggest dong it in the subform's
BeforeUpdate event procedure like so:
Dim strCriteria As String, strMessage As String
Dim intQuantShippedSoFar as Integer
Dim intQuantProposedForShipping As Integer
strMessage = "Ordered quantity for this product exceeded."
strCriteria = "OrderID = " & Me.OrderID & _
" And ProductID = " & Me.ProductID
If Me.NewRecord Then
intQuantShippedSoFar = DLookup("Quantity", "OrderDetails", strCriteria)
intQuantProposedForShipping = DSum("Quantity", "OrderDetailLoads",
strCriteria) _
+ Me.Quantity
Else
intQuantShippedSoFar = DLookup("Quantity", "OrderDetails", strCriteria)
& _
- Me.Quantity.OldValue
intQuantProposedForShipping = DSum("Quantity", "OrderDetailLoads",
strCriteria) _
+ Me.Quantity – Me.Quantity.Oldvalue
End If
If intQuantProposedForShipping > intQuantShippedSoFar Then
MsgBox strMessage, vbInformation, "Invalid Operation"
Cancel = True
End If
The user won't be able to save the subform record until a valid quantity has
been entered. If entering data via a subform in a Loads form you could
incorporate similar validation.
Jae Hood said:
Ken, your approach is excellent.
It makes sense because the sales person has to fill in the order table and
the order details before he can dissect his load quantities.
So would I be able to make a button on the order form like "Load Breakdown"
that opens the OrderDetailsLoads table as a continuous form?
Also I'm thinking if I use your approach, can't I eliminate the entire
LoadDetails table?
I would be able to specify the LoadID using the OrderDetailsLoads, or would
it be wiser to keep it in order to group the multiple products on one load
and view it more clearly?
I really appreciate your suggestions.