Hi
I have solved my problem with a work around, but I thought I would share it anyway in case anybody can shed any light on why it didn't work.
The application is for handling periodic stock takes.
I have a table containing a list of parts and quantities exported from the accounts application, with a field containing a foreign key that indicates the date the data was exported. A second table contains a summary of the counts from the stock take, again with the same foreign key field.
The following query is supposed to give a list of all the stock items where there is a variance in the stock quantity between the accounts application and the actual stock count:
SELECT T0.PartNo, T0.DESCRIPTION, T0.QTY_IN_STOCK, nz([T1].[Quantity],0) AS StockCount,
FROM (SELECT PartNo, Description, QTY_IN_STOCK FROM tblStockBeforeStockEntry WHERE StockTakeKey=Stock_Take_Key()) AS T0
LEFT JOIN (SELECT PartNo, Quantity, StockTakeKey FROM tblStockTakeExplodedStock WHERE StockTakeKey=Stock_Take_Key()) AS T1
ON T0.PartNo=T1.PartNo
WHERE (((Round([T0].[QTY_IN_STOCK],0)-Round(nz([T1].[Quantity],0),0))<>0))
ORDER BY T0.PartNo;
Stock_Take_Key() is a vba function that returns the currently selected foreign key.
When I run the above query the outer join does not work, so that parts that have a stock quantity in the accounts application but no stock count records are not shown. If I hard code the current foreign key into the sql statement to replace Stock_Take_Key() then the outer join works fine.
The above query is the data source for a report. My work around was to generate the above query including the hard-coded foreign key in vba and store it in a global variable, then set the record source to this variable in the On Open event procedure for the report.