I have a daily inventory on hand entry form. I want to get the last inventory on hand for each item to use as the opening inventory. In my query for the record source of the form I used a subquery with select max:
to obtain the last inventory date for the item (I still need to figure out how to use that date to get the hard count from that record) this works fine however I am left with an un-updateable query and I need to be able to enter the new inventory on hand in the form. I thought dlookup with dmax would be a good solution but I have been unable to get that to work. We often correct old inventory amounts so I wanted to avoid a static or stored opening inventory. Any help or suggestions would be greatly appreciated.
Code:
SELECT tblInventoryLineItems.ItemID, tblInventoryLineItems.ItemSales, tblInventoryLineItems.ItemPurchases, tblInventoryLineItems.ItemAdjustment, (select max ([inventory date])
From tblinventory as old inner join tblinventorylineitems as oldline on old.[inventory id] = oldline.dailyid
Where old.[inventory date] < tblinventory.[inventory date]
And oldline.itemid = tblinventorylineitems.itemid) AS InvOpen, tblInventoryLineItems.HardCount, ([OpeningInventory]+[ItemPurchases])-([ItemSales]+[ItemAdjustment]+[HardCount]) AS Deviation
FROM tblinventory INNER JOIN tblInventoryLineItems ON tblinventory.[Inventory ID] = tblInventoryLineItems.DailyID;
Last edited: