Do I need a subquery?

B

Barry

Hi:
I am having problems creating a query to show cars with WorkOrders. The
tables involved are Customers (CustomerID as PK), CustomerCars (CardID as PK,
CustomerID as FK) and WorkOrders (WorkOrderID as PK, CustomerID as FK, CarID
as FK). I would like to have a query as the recordsource for a listbox that
shows the WorkOrderID, CustomerName, CarYear, CarMake and CarModel. My
problem is that I keep getting all of the customers' cars with the same
WorkOrderID. ie If I am the customer and I have 5 cars listed in CustomerCars
they all show in the query and I only want the one associated with the
WorkOrderID. Any help is greatly appreciated. I hope that I have explained
the probelm well enough. Please let me know if there are additional
questions.
Thanks,
Barry
 
K

KARL DEWEY

Try this --
SELECT WorkOrderID, CustomerName, CarYear, CarMake and CarModel
FROM (WorkOrders INNER JOIN Customers ON WorkOrders.CustomerID =
Customers.CustomerID) INNER JOIN CustomerCars ON WorkOrders.CarID =
CustomerCars.CarID
WHERE WorkOrderID = [Forms]![YourFormName]![Listbox];
 
B

Barry

Karl:
Thanks for the reply. It is working for my WorkOrders table however, it is
not working on my Estimates table. I will need to check that table and see
if I have some sort of corruption going on there. Again, thanks for your
help.
Sincerely,
Barry

KARL DEWEY said:
Try this --
SELECT WorkOrderID, CustomerName, CarYear, CarMake and CarModel
FROM (WorkOrders INNER JOIN Customers ON WorkOrders.CustomerID =
Customers.CustomerID) INNER JOIN CustomerCars ON WorkOrders.CarID =
CustomerCars.CarID
WHERE WorkOrderID = [Forms]![YourFormName]![Listbox];

--
Build a little, test a little.


Barry said:
Hi:
I am having problems creating a query to show cars with WorkOrders. The
tables involved are Customers (CustomerID as PK), CustomerCars (CardID as PK,
CustomerID as FK) and WorkOrders (WorkOrderID as PK, CustomerID as FK, CarID
as FK). I would like to have a query as the recordsource for a listbox that
shows the WorkOrderID, CustomerName, CarYear, CarMake and CarModel. My
problem is that I keep getting all of the customers' cars with the same
WorkOrderID. ie If I am the customer and I have 5 cars listed in CustomerCars
they all show in the query and I only want the one associated with the
WorkOrderID. Any help is greatly appreciated. I hope that I have explained
the probelm well enough. Please let me know if there are additional
questions.
Thanks,
Barry
 

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