Question : outer joins in MS Access

I want to be able to have MTD, YTD and LTD equal to the following if the select query fails to return any results
0 as MTD
 CInt([dbo_Item.SubDescription2]) as YTD
and
CInt([dbo_Item.SubDescription3]) as LTD
1:
2:
3:
SELECT dbo_Item.BarcodeNumber, dbo_Item.Description, Sum(IIf(Month([Time])=Month(Date()) And Year([Time])=Year(Date()),dbo_TransactionEntry.Quantity,Null)) AS MTD, CInt([SubDescription2])+Sum(IIf(Year([Time])=Year(Date()),dbo_TransactionEntry.Quantity,Null)) AS YTD, Sum([dbo_TransactionEntry.Quantity])+CInt([dbo_Item.SubDescription3]) AS LTD, dbo_Item.SubDescription1, dbo_Item.SubDescription2, dbo_Item.SubDescription3
FROM (dbo_Transaction INNER JOIN dbo_TransactionEntry ON dbo_Transaction.TransactionNumber = dbo_TransactionEntry.TransactionNumber) INNER JOIN dbo_Item ON dbo_TransactionEntry.ItemID = dbo_Item.ID
GROUP BY dbo_Item.BarcodeNumber, dbo_Item.Description, dbo_Item.SubDescription1, dbo_Item.SubDescription2, dbo_Item.SubDescription3;

Answer : outer joins in MS Access

Try this change to you database.  I broke the query into three separate queries.  First to do a right join to include all items from dbo_Item and only those matching from dbo_TransactionEntry.  Then I added a second query to add in the Time (to get MTD, YTD and LTD) from the dbo_Transaction table.  Then I added a final master query (QS-LifeTimeSchedule Master) to combine that data back upto the Barcode Number level and add in the static amounts from the SubDescription2 and SubDescription3 fields.  I modified your subform to pull from the master query so the timeframes are accurate for each record you select in the main form, and you don't need your "helper" fields on the right.

1st query:
SELECT dbo_Item.BarcodeNumber, dbo_Item.Description, dbo_TransactionEntry.TransactionNumber, Sum(dbo_TransactionEntry.Quantity) AS Quantity
FROM dbo_TransactionEntry RIGHT JOIN dbo_Item ON dbo_TransactionEntry.ItemID = dbo_Item.ID
GROUP BY dbo_Item.BarcodeNumber, dbo_Item.Description, dbo_TransactionEntry.TransactionNumber;



2nd query:
SELECT [QS-LifeTime Schedule Prelim].BarcodeNumber, [QS-LifeTime Schedule Prelim].Description, Sum(IIf(Month([Time])=Month(Date()) And Year([Time])=Year(Date()),[Quantity],0)) AS MTD, Sum(IIf(Year([Time])=Year(Date()),[Quantity],0)) AS YTD, Sum(nz([Quantity],0)) AS LTD
FROM dbo_Transaction RIGHT JOIN [QS-LifeTime Schedule Prelim] ON dbo_Transaction.TransactionNumber = [QS-LifeTime Schedule Prelim].TransactionNumber
GROUP BY [QS-LifeTime Schedule Prelim].BarcodeNumber, [QS-LifeTime Schedule Prelim].Description;


3rd query:
SELECT [QS-LifeTime Schedule Prelim2].BarcodeNumber, [QS-LifeTime Schedule Prelim2].Description, [QS-LifeTime Schedule Prelim2].MTD AS MTDAmt, [QS-LifeTime Schedule Prelim2].YTD+[T-LifeTime Static Data].YTD AS YTDAmt, [QS-LifeTime Schedule Prelim2].LTD+[T-LifeTime Static Data].LTD AS LTDAmt
FROM [QS-LifeTime Schedule Prelim2] LEFT JOIN [T-LifeTime Static Data] ON [QS-LifeTime Schedule Prelim2].BarcodeNumber = [T-LifeTime Static Data].BarcodeNumber
GROUP BY [QS-LifeTime Schedule Prelim2].BarcodeNumber, [QS-LifeTime Schedule Prelim2].Description, [QS-LifeTime Schedule Prelim2].MTD, [QS-LifeTime Schedule Prelim2].YTD+[T-LifeTime Static Data].YTD, [QS-LifeTime Schedule Prelim2].LTD+[T-LifeTime Static Data].LTD;



Random Solutions  
 
programming4us programming4us