OK.
Rewrite of your query to handle a problem.
== DISTINCT and GROUP BY have the same effect on returned records, so you
don't need DISTINCT in this query.
== Last returns the value of the field in the LAST record accessed by the
query for the group. You want MAX to get the latest date.
== It is more efficient to use a WHERE clause to limit the records returned
before they are aggregated. Use HAVING clause when you want to filter against
the aggregated result.
SELECT OrderDetails.ProductName2
, OrderDetails.PrdtID
, ShipAddress.CID
, Max(ShipAddress.ShippedDate) AS LastShippedDate
FROM ShipAddress INNER JOIN OrderDetails ON ShipAddress.OID = OrderDetails.OID
WHERE ShipAddress.CID=[Forms]![OrderForm]![CID]
GROUP BY OrderDetails.ProductName2, OrderDetails.PrdtID, ShipAddress.CID
HAVING MAX(ShipAddress.ShippedDate)<=Date()-14
ORDER BY OrderDetails.PrdtID;
SELECT OrderDetails.ProductName2
, OrderDetails.PrdtID
, ShipAddress.CID
, Max(ShipAddress.ShippedDate) AS LastShippedDate
FROM ShipAddress INNER JOIN OrderDetails ON ShipAddress.OID = OrderDetails.OID
WHERE (((ShipAddress.CID)=[Forms]![OrderForm]![CID]))
GROUP BY OrderDetails.ProductName2, OrderDetails.PrdtID, ShipAddress.CID
ORDER BY OrderDetails.PrdtID;
Since you are restricting both queries to the same CID you don't need that at
in the join, but I think you do need the LastShipDate as part of the join.
SELECT CustomerSales.*
FROM CustomerSales LEFT JOIN CustomerNoSales
ON CustomerSales.PrdtID = CustomerNoSales.PrdtID
AND CustomerSales.LastShippedDate = CustomerNoSales.LastShippedDate
WHERE CustomersNoSales.PrdtID is Null
John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
John I want to thank you for your time, I was looking at my initial request
for help and I failed to mention that the records I am looking for are from
only one customer. Here is the 2 queries:
S N I P
.