Full Version: Relationship Troubles
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
jawag
No, I am not getting personal. tongue.gif I have a relationship set up so that all the values from one table are shown and only the values from another query are shown where the fields are equal. The data results in two lines of information. One line has all the data, and another line has the same data as the first line, but without the data from the query. I would like to eliminate the line that does not contain all the information possible, but I still want to be able to have data from one table even if data from the query doesn't exist. I have included the code in case it helps.

SELECT [Bag Inventory].Description, [Bag Inventory].Quantity, [Bag Inventory].[Reorder Point], [Product Table].[Blocks per box], [Blocks per box]*[Quantity Expected] AS Bags, IIf([Quantity]<[Reorder Point],"Reorder"," ") AS Reorder, [Bag Inventory Query].[Pack date], [Bag Inventory Query].[Quantity Expected]
FROM [Bag Inventory Query] RIGHT JOIN ([Bag Inventory] INNER JOIN [Product Table] ON [Bag Inventory].[Oracle Item] = [Product Table].[Bag Oracle Number]) ON [Bag Inventory Query].Item = [Product Table].[Product ID]
GROUP BY [Bag Inventory].Description, [Bag Inventory].Quantity, [Bag Inventory].[Reorder Point], [Product Table].[Blocks per box], [Blocks per box]*[Quantity Expected], IIf([Quantity]<[Reorder Point],"Reorder"," "), [Bag Inventory Query].[Pack date], [Bag Inventory Query].[Quantity Expected]
HAVING ((([Bag Inventory].Description)=[Forms]![Main Menu]![Combo27])) OR ((([Forms]![Main Menu]![Combo27]) Is Null));


Thanks,
Jake
jzwp11
First, I do not see any aggregate functions in your SELECT clause, so I do not see the point in having the GROUP BY. I think Access sometimes adds that. I would remove the GROUP BY clause which will force you to change HAVING to WHERE. So, the query should look like this:

SELECT [Bag Inventory].Description, [Bag Inventory].Quantity, [Bag Inventory].[Reorder Point], [Product Table].[Blocks per box], [Blocks per box]*[Quantity Expected] AS Bags, IIf([Quantity]<[Reorder Point],"Reorder"," ") AS Reorder, [Bag Inventory Query].[Pack date], [Bag Inventory Query].[Quantity Expected]
FROM [Bag Inventory Query] RIGHT JOIN ([Bag Inventory] INNER JOIN [Product Table] ON [Bag Inventory].[Oracle Item] = [Product Table].[Bag Oracle Number]) ON [Bag Inventory Query].Item = [Product Table].[Product ID]
WHERE ((([Bag Inventory].Description)=[Forms]![Main Menu]![Combo27])) OR ((([Forms]![Main Menu]![Combo27]) Is Null));

I am guessing that the above changes will not eliminate the extra line. If my guess is correct, then I believe the problems lies with the bag inventory--product table. You might want to create a query that does the joining between the bag inventory table and the product table and then do your RIGHT JOIN to that query.
jawag
Unfortunately, making another query with the relationship did not work. I appreciate you taking a look at this. Let me know if you have any other thoughts.
Jeff B.
Please post the SQL statement of that "other" query...
jzwp11
When you run the bag inventory--product table, do you get 2 records per oracle item#/Bag Oracle Item #? Can you post the relationship diagram and/or a copy of the database with any sensitive data removed?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.