Report/Query Filtering

M

Markis

I'm trying to make a custom report/query. What I have is a purchase order
database. The tables are "Customers", "PurchaseOrders",
"PurchaseOrderDetails" and "Products". The products have a part number and
are either a "sample" or "full-part". What I want to do is produce a report
that shows only the purchase orders where a customer ordered a "sample" AND a
"full-part" of that sample. For instance...if John Smith ordered a sample of
"XYZ Gadget" and then ordered the actual part "XYZ Gadget", I would want it
to show on the report. Similarly, if Jack Bell ordered a sample for "XYZ
Gadget" and didn't end up ordering that part or maybe ordered a "XYT Gizmo",
I would not want that to show up on the report. Any help is appreciated.
 
D

DStegon via AccessMonster.com

Do you have a table the relates (joins) the "sample" ID and the "full-part"
ID. You will need to have a join table that will allow you to make this
relationship. After that the qry is quite simple. You will have the PO with
the part_id number inner join to the "join" table part1 and part2 inner
joined to another instance of the PO table (PO1) part_ID with a where clause
for both PO tables filtering on the customerID.

If you have your table structure correct this should be a piece of pie....
 
M

Markis

If I am understanding you correctly, I do not have a separate table. All
parts are stored in a single table. There is a field in that table called
"classification" which links to another table that stores all classification
types, ie "Sample", "Molded", etc. All classifications are a "full-part"
except for "Sample". So when a customer orders a part, they can order "XYZ
Gadget-full-part", qty. 5; and they can have an order for "XYZ
Gadget-sample", qty. 1. I want to capture all those instances that have a
customer ordering that sample and full-part.

I hope I explained it better. It is a bit confusing. Thanks.
 
M

Markis

This may help. Here are results of a query. The [CustomerID] and [LastName]
are in the Customers table; the [ProductModelNumber] is in the Products table
and [ProductClassification] is in the Classifications table. What I can’t
seem to filter out are those records that are with the " * ". I only want to
return those records.

CustomerID Last name Product model number Product classification
2 Barry D-70-5555-1 FullPart
3 Jones D-80-INT-665 Samples
3 Jones D-80-INT-667 Samples
4 Davis D-80-INT-8 Samples
4 Davis DL-200-INT-8 Samples
5 Minto XX-100-0-176 FullPart
5 Minto XX-100-0-1 FullPart
**6 Allen XX-155-INT-344 Samples
**6 Allen XX-155-INT-7 Samples
**6 Allen XX-155-0-344 FullPart
7 Rundi XX-100-0-1 FullPart
7 Rundi XX-100-0-1 FullPart
7 Rundi XX-100-0-1 FullPart
7 Rundi XX-100-0-1 FullPart
7 Rundi XX-100-0-1 FullPart
7 Rundi CMP-RC-0-0 FullPart
7 Rundi CMP-RD-0-0 FullPart
**8 Crumb XX-155-INT-1 Samples
**8 Crumb XX-155-INT-176 Samples
**8 Crumb XX-155-INT-224 Samples
**8 Crumb XX-155-INT-14 Samples
**8 Crumb XX-155-INT-38 Samples
**8 Crumb XX-155-INT-15 Samples
**8 Crumb XX-155-0-1 FullPart
 
D

DStegon via AccessMonster.com

Oh. Ok. Well first off, the sample and the full part are not identical part
numbers that the only difference is the classification. Because of this you
are going to have to create a relation (join) table in which you store both
product_id's so that you can tell the database that the part numbers are
related (one being the full part one being the sample). If the part number
had identical part numbers and were only different by the classification then
you could write a query comparing the product_id and quering the data with an
OR statement.

sample qry for dup products with different classifications
SELECT Customers.CustomerID, Customers.CompanyName, Customers.ContactName,
Orders.OrderID, [Order Details].ProductID, [Order Details].Quantity, Products.
ProductName, Categories.CategoryID, [Order Details_1].OrderID, Products_1.
ProductName, Categories_1.CategoryID
FROM Categories AS Categories_1 INNER JOIN (Products AS Products_1 INNER JOIN
([Order Details] AS [Order Details_1] INNER JOIN (Orders AS Orders_1 INNER
JOIN ((Categories INNER JOIN Products ON Categories.CategoryID = Products.
CategoryID) INNER JOIN ((Customers INNER JOIN Orders ON Customers.CustomerID
= Orders.CustomerID) INNER JOIN [Order Details] ON Orders.OrderID = [Order
Details].OrderID) ON Products.ProductID = [Order Details].ProductID) ON
Orders_1.CustomerID = Customers.CustomerID) ON [Order Details_1].OrderID =
Orders_1.OrderID) ON Products_1.ProductID = [Order Details_1].ProductID) ON
Categories_1.CategoryID = Products_1.CategoryID
WHERE (((Products.ProductName) Like "XX-155-0-344") AND ((Categories.
CategoryID)=1) AND (([Order Details_1].OrderID)<>[Orders].[OrderID]) AND (
(Products_1.ProductName) Like "XX-155-0-344") AND ((Categories_1.CategoryID)
=2));


That does not seem to be your case here. See, you have to be able to tell
the data that two different numbers are somehow related... see... XX-155-INT-
344 and XX-155-0-344 are different to the computer. Now, if the sample
always has "INT" and the full part ALWAYS has "0" in the exact same spot in
the product number then you could write a parsing function to get the "part
less the class" and then search the data for that, but that seems like a bit
of a mess. To solve easily create a table that will allow you to join the
two part together

tbl_Prod_FP_Sample_Join
Prod_FP_Sample_ID
Prod_FP
Prod_Sample

create a form that will allow you to join one product to another and save it
to the table. Then a query of the table becomes a bit easier.

you put two order tables, the join table, the customer table, two order
detail tables and link them accordingly then filtering them on the product of
either the sample or full part part number or just have it show you all of
the data that is related like this:

SELECT Customers.CustomerID, Customers.CompanyName, Customers.ContactName,
Orders.OrderID, Products.ProductID, Products.ProductName, [Order Details].
UnitPrice, [Order Details].Quantity, Categories.CategoryName, Orders_1.
OrderID, [Order Details_1].ProductID, Products_1.ProductName, [Order
Details_1].UnitPrice, [Order Details_1].Quantity, Categories_1.CategoryName
FROM Categories AS Categories_1 INNER JOIN (((Products AS Products_1 INNER
JOIN [Order Details] AS [Order Details_1] ON Products_1.ProductID = [Order
Details_1].ProductID) INNER JOIN Orders AS Orders_1 ON [Order Details_1].
OrderID = Orders_1.OrderID) INNER JOIN (Product_Join INNER JOIN ((Categories
INNER JOIN Products ON Categories.CategoryID = Products.CategoryID) INNER
JOIN (Customers INNER JOIN (Orders INNER JOIN [Order Details] ON Orders.
OrderID = [Order Details].OrderID) ON Customers.CustomerID = Orders.
CustomerID) ON Products.ProductID = [Order Details].ProductID) ON
Product_Join.Prod1 = Products.ProductID) ON (Product_Join.Prod2 = Products_1.
ProductID) AND (Orders_1.CustomerID = Customers.CustomerID)) ON Categories_1.
CategoryID = Products_1.CategoryID
WHERE (((Categories.CategoryID)=1) AND ((Categories_1.CategoryID)=3));

the assumption above is that Classification ( CategoryID ) for fullpart is 1
and sample is 3. If you want to query on a specific customer you just add
that to the query or on a certain part number add that to your query in the
where clause. You can add what ever fields you want from your table to give
you the info you want to see or have this as the source for a report and then
place whatever fields you want on the report.


Also, I would not Store the words Full Part or Sample, but store the
Classification ID (long/autonumber) in your product table. Much easier to
filter on a number than text because you dont have to worry about wild cards
or quotes.

tbl_Prod_Class
Prod_Class_ID as autonum
Prod_Class as text

tbl_Prod
tbl_Prod_ID
Product
Product_Description
Prod_Class_ID
blah
blah


This may help. Here are results of a query. The [CustomerID] and [LastName]
are in the Customers table; the [ProductModelNumber] is in the Products table
and [ProductClassification] is in the Classifications table. What I can’t
seem to filter out are those records that are with the " * ". I only want to
return those records.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top