Question : Inventory Allocation and FIFO

I have a database for tracking materials used for fabrication. I need the ability to allocate parts using First In First Out (FIFO) based on quantity available. Lets say I have filtered my part source to the following data from qryPurchaseOrders. I have a total available quantity of 52 for the part number listed, but that quantity comes from three purchase orders. I need to allocate a quantity of 35 to table tblAllocated starting with the first purchase order, progressing through the additional purchase orders until the quantity of 35 has been allocated.

Lets say the form is called frmAllocate, the text box used to enter the quantity is called txtQty, and the button for the VBA is called btnEnter.

The SQL for qryPurchaseOrders is:
SELECT pchord.ordnum AS PONumber, pchord.orddte AS [Date], pcorln.prtnum AS PartNumber, pcorln.linqty AS Qty
FROM pchord INNER JOIN pcorln ON pchord.recnum = pcorln.recnum
WHERE (((pcorln.prtnum)= 2011300) AND ((pchord.jobnum)=106024));

tblAllocated has the structure shown.

qryPurchaseOrders                  
PONumber      Date      PartNumber      Qty      
1234      12/30/2008      2011300      20      
1250      1/18/2009      2011300      10      
1255      1/29/2009      2011300      22      
                        
                        
I need to allocate a quantity of 35 to tblAllocated            
                        
                        
tblAllocated                  
ID      PONumber      PartNumber      Qty      DateAllocated
100      1234      2011300      20      2/4/2009
101      1250      2011300      10      2/4/2009
102      1255      2011300      5      2/4/2009

What is the VBA to accomplish this?
Thanks!!

Answer : Inventory Allocation and FIFO

Here ya go, George...

I suggest you play with my database to see if it really does what you want before you try to use it in the production DB.

Note that I modified qryPurchaseOrders to allow input of part number and job number to the process as parameters and to ensure the POs are accessed in ascending order by date.

To run the procedure, first make sure that you have a reference to 'Microsoft ActiveX Data Objects' which is needed to open queries and tables using ADO.  To check this, use Alt-F11 to get to the Visual Basic window, then 'Tools'/'References' will show you the list. If there is no check by 'Microsoft ActiveX Data Objects' , find it and check it and click 'OK'.  Use the latest version (2.8 in my case).

Then, In the Immediate window of Visual Basic, type 'call GetParts(,,)' and press enter.  For my database, part number = 2011300 and job number = 106024.  I used these quantities for sucessive runs in order: 5,10,10,30.  After each run, check the contents of tblAllocated to see if the records are as you expected.  You can look at the records generated by my tests before you start.  You will have to delete the contents of tblAllocated in order to have some parts available because I used them all.

Further testing with more PO data is advisable.

Dan
 
Demo of code to perform a custom FIFO process.
 
Random Solutions  
 
programming4us programming4us