Return all products not associated with a variable (1 Viewer)

brharrii

Registered User.
Local time
Yesterday, 18:34
Joined
May 15, 2012
Messages
272
I use access 2010. I have a form that allows the user to assign products to operations. Each operation can produce multiple products and each product can be produced at multiple operations. I manage this many-to-many relationship through the use of a third table that stores primary keys for associated products / operations.

tblOperation
tblProducts
tblOperationProducts

The query im trying to design will populate a listbox on the form that contains products which are available to be added to a given operation. In addition to the listbox there is also a combobox that allows the user to select the operation they want to add products to. As the user selects an operation, the query behind the listbox should return records for all products except the ones that have already been assigned to the operation selected in the combobox.

So far I've been able to make the listbox return all products always or return products that haven't been assigned to any operation at all, but I'm struggling to formulate the logic in my mind on how to show only products that have no association (through the tblOperationProducts table) with the operation selected in the forms combobox.

Can anyone help me with this?

Thanks!

Bruce


This is the query I have right now, it's not working but maybe it will give an idea as to where I'm trying to go with it:

Code:
Select tblProducts.ProductID
From tblProducts
EXCEPT
SELECT tblProducts.ProductID
FROM tblOperation RIGHT JOIN (tblProducts RIGHT JOIN tblOperationProductMM ON tblProducts.ProductID = tblOperationProductMM.ProductIDMM) ON tblOperation.OperationID = tblOperationProductMM.OperationIDMM
WHERE (((tblOperation.OperationID)=[Forms]![frmOperationProducts]![cboOperation]));
 
Last edited:

brharrii

Registered User.
Local time
Yesterday, 18:34
Joined
May 15, 2012
Messages
272
I figured out how to do this using access find unmatched query wizard:

SELECT tblProducts.ProductID, tblProducts.ProductNumber, tblProducts.ProductDesc, tblProducts.ProductSpecies
FROM tblProducts LEFT JOIN Query1 ON tblProducts.[ProductID] = Query1.[ProductID]
WHERE (((Query1.ProductID) Is Null));

Query1:
SELECT tblProducts.ProductID
FROM tblOperation RIGHT JOIN (tblProducts RIGHT JOIN tblOperationProductMM ON tblProducts.ProductID = tblOperationProductMM.ProductIDMM) ON tblOperation.OperationID = tblOperationProductMM.OperationIDMM
WHERE (((tblOperation.OperationID)=[Forms]![frmOperationProducts]![cboOperation]));
 

Users who are viewing this thread

Top Bottom