Relevant Tables
#One#
+----------+ +--------------+
|Quotations| ---> |PurchaseOrders|
+----------+ | +--------------+
<One> | <Many> |
| v #Many#
| +-----------+ +------------+
v |QuotedItems| ---> |OrderedItems|
+-----------+ +------------+
<Many> {One} {Many}
Form/Subform
PurchaseOrders
- Master Form, many-to-one with OrderedItems
OrderedItems
- Datasheet-style subform, many-to-one with PurchaseOrders
Quotations
- A table that is one-to-many with PurchaseOrders
and used for querying
QuotedItems
- A table that is one-to-many with OrderedItems
and used for querying
Combo Box
The Item
control resides in the OrderedItems
subform. It is a combo box that runs the following ad hoc query:
SELECT [ID], [Code]
FROM [QuotedItems]
WHERE [QuotedItems].[Quotation] = Forms.PurchaseOrders.Quotation;
The combo box query runs the way I expect it to; there are no problems here. The [ID]
column is hidden from view (column-width is zero).
Problem
The problem comes when I try to append values from the QuotedItems
table (filtered on the current quotation ID selected in the form) at the click of a button.
I created an append query to achieve this called CopyQuotedItems2OrderedItems
:
INSERT INTO OrderedItems ( PurchaseOrder, Item, Quantity )
SELECT PurchaseOrders.ID, QuotedItems.Item, QuotedItems.Quantity
FROM ( Quotations
INNER JOIN
PurchaseOrders
ON Quotations.ID = PurchaseOrders.Quotation
)
INNER JOIN
QuotedItems
ON Quotations.ID = QuotedItems.Quotation
WHERE (((Quotations.ID)=[Forms].[PurchaseOrders].[Quotation]));
The Copy Quoted Items button in the PurchaseOrders
form then runs the following code:
Private Sub CopyQuotedItems_Click()
DoCmd.OpenQuery "CopyQuotedItems2OrderedItems"
End Sub
The append works as it should. However, the second field of the INSERT
statement - which ties in to the Item
control does not display anything, even after refreshing. The only way to make the item's Code
visible is to select the combo box and choose an item from it.
1000 words...
Before clicking Copy Quoted Items (note that combo box has two entries in this case):
After Clicking Copy Quoted Items:
Questions
- Firstly, why can't I see my
Code
by default after running the append query? Is it because the value inserted by the append query is not bound to the combo box in some way? - Secondly, am I barking up the wrong tree? If so, how else can I get it to display
the
Code
column automatically?