I have been banging my head on a wall for a while trying to solve this, and I am hoping someone can put me out of my misery! I have a query that draws from 4 tables and adds stock levels from "in" and "out" fields. However, a seperate table also tracks what stock is used on jobs. I have tried to add this data into the query via tables, but it throws everything out of whack no matter what I try. To get around this issue, I am trying to use dlookup to fill in the "stockused" portion.
This seems to work when I use "StockID" as the only criteria. But I need to also use "StorageID" as a second criteria and this is where I am running into a problem. there are multiple "StorageID" fields in seperate tables, so the query didn't like it. I renamed the query entry to "Store: StorageID" and used "Store" in my dlookup instead. Now when I run the query a popup prompts me to enter "Store". If I enter any number, the query runs and seems to work just fine (each return shows the correct number of stockused for the given stockid and storageid).
Why is the popup appearing??? So long as ANY number is entered (even numbers that have no relation to any storageids in any table), the query runs properly (text crashes the program).
My dlookup is: Expr4: DLookUp("[sumofqtyused]","[qrysumstockused]","benchstockidfk = " & [stockid] & " AND storageID = " & [store])
If it helps, my query (qrySumStockfm) is:
SELECT tblStockStorageMM.StockID, Sum(Round([QtyIn],3)) AS Expr1, Sum(Round([QtyOut],3)) AS Expr2, tblBenchStock.Nomenclature, tblStorage.StorageArea, tblLocation.LocationName, tblStorage.StorageID AS Store, tblLocation.LocationID, tblBenchStock.RedLevel, tblBenchStock.TargetLevel, tblBenchStock.[P/N], tblBenchStock.Manufacturer, tblBenchStock.UnitofIssue, tblBenchStock.QtyPerUnit, tblBenchStock.Cost, Sum((Nz([QtyIn])-Nz([qtyout]))*Nz([qtyperunit])) AS TotalStockPerItem, DLookUp("[sumofqtyused]","[qrysumstockused]","benchstockidfk = " & [stockid] & " AND storageID = " & [store]) AS Expr4
FROM (tblLocation INNER JOIN tblStorage ON tblLocation.LocationID = tblStorage.LocationID) INNER JOIN (tblBenchStock INNER JOIN tblStockStorageMM ON tblBenchStock.BenchStockID = tblStockStorageMM.StockID) ON tblStorage.StorageID = tblStockStorageMM.StorageID
GROUP BY tblStockStorageMM.StockID, tblBenchStock.Nomenclature, tblStorage.StorageArea, tblLocation.LocationName, tblStorage.StorageID, tblLocation.LocationID, tblBenchStock.RedLevel, tblBenchStock.TargetLevel, tblBenchStock.[P/N], tblBenchStock.Manufacturer, tblBenchStock.UnitofIssue, tblBenchStock.QtyPerUnit, tblBenchStock.Cost, DLookUp("[sumofqtyused]","[qrysumstockused]","benchstockidfk = " & [stockid] & " AND storageID = " & [store])
ORDER BY tblBenchStock.Nomenclature;
I'd appreciate any help on this!
This seems to work when I use "StockID" as the only criteria. But I need to also use "StorageID" as a second criteria and this is where I am running into a problem. there are multiple "StorageID" fields in seperate tables, so the query didn't like it. I renamed the query entry to "Store: StorageID" and used "Store" in my dlookup instead. Now when I run the query a popup prompts me to enter "Store". If I enter any number, the query runs and seems to work just fine (each return shows the correct number of stockused for the given stockid and storageid).
Why is the popup appearing??? So long as ANY number is entered (even numbers that have no relation to any storageids in any table), the query runs properly (text crashes the program).
My dlookup is: Expr4: DLookUp("[sumofqtyused]","[qrysumstockused]","benchstockidfk = " & [stockid] & " AND storageID = " & [store])
If it helps, my query (qrySumStockfm) is:
SELECT tblStockStorageMM.StockID, Sum(Round([QtyIn],3)) AS Expr1, Sum(Round([QtyOut],3)) AS Expr2, tblBenchStock.Nomenclature, tblStorage.StorageArea, tblLocation.LocationName, tblStorage.StorageID AS Store, tblLocation.LocationID, tblBenchStock.RedLevel, tblBenchStock.TargetLevel, tblBenchStock.[P/N], tblBenchStock.Manufacturer, tblBenchStock.UnitofIssue, tblBenchStock.QtyPerUnit, tblBenchStock.Cost, Sum((Nz([QtyIn])-Nz([qtyout]))*Nz([qtyperunit])) AS TotalStockPerItem, DLookUp("[sumofqtyused]","[qrysumstockused]","benchstockidfk = " & [stockid] & " AND storageID = " & [store]) AS Expr4
FROM (tblLocation INNER JOIN tblStorage ON tblLocation.LocationID = tblStorage.LocationID) INNER JOIN (tblBenchStock INNER JOIN tblStockStorageMM ON tblBenchStock.BenchStockID = tblStockStorageMM.StockID) ON tblStorage.StorageID = tblStockStorageMM.StorageID
GROUP BY tblStockStorageMM.StockID, tblBenchStock.Nomenclature, tblStorage.StorageArea, tblLocation.LocationName, tblStorage.StorageID, tblLocation.LocationID, tblBenchStock.RedLevel, tblBenchStock.TargetLevel, tblBenchStock.[P/N], tblBenchStock.Manufacturer, tblBenchStock.UnitofIssue, tblBenchStock.QtyPerUnit, tblBenchStock.Cost, DLookUp("[sumofqtyused]","[qrysumstockused]","benchstockidfk = " & [stockid] & " AND storageID = " & [store])
ORDER BY tblBenchStock.Nomenclature;
I'd appreciate any help on this!