Hello,
I need help creating a query that will out put the short date when you take into account the on hand inventory minus the usage plus the deliveries. Thanks to arnelgp with helping on finding the stock out date when I take the on hand inventory minus the usage but now I need to add in the incoming inventory.
arnelgp's Code is below as well as all my query tables.
For example Arnelgp code finds the stock out date of Item 548-542 as 5/10/2018 However when I account for the Delivery of qty. 3 it moves the stock out date to 5/25/2018
The output that I am looking to get is:
ITEM Stock out Date
548-542 5/25/2018
645-214 6/21/2018
Thank you in advance for the help.
Usage Query
Usage Query
Item. Usage date. Qty. used
548-542 4/6/2018 1
548-542 4/16/2018 2
548-542 4/24/2018 1
548-542 5/2/2018 1
548-542 5/10/2018 1
548-542 5/18/2018 1
548-542 5/25/2018 1
645-214 4/9/2018 2
645-214 5/4/2018 2
645-214 5/8/2018 1
645-214 5/23/2018 2
645-214 6/21/2018 2
645-214 7/6/2018 1
CurrentInv Query
Item. Current Qty.
548-542 5
645-214 4
DeliveryInv Query
ITEM PLANDELDATE ORDQTY
548-542 4/14/2018 3
645-214 4/25/2018 4
I need help creating a query that will out put the short date when you take into account the on hand inventory minus the usage plus the deliveries. Thanks to arnelgp with helping on finding the stock out date when I take the on hand inventory minus the usage but now I need to add in the incoming inventory.
arnelgp's Code is below as well as all my query tables.
For example Arnelgp code finds the stock out date of Item 548-542 as 5/10/2018 However when I account for the Delivery of qty. 3 it moves the stock out date to 5/25/2018
The output that I am looking to get is:
ITEM Stock out Date
548-542 5/25/2018
645-214 6/21/2018
Thank you in advance for the help.
Code:
Option Compare Database
Option Explicit
Dim db As DAO.Database
Public Function fnStockOutDate(partNumber As Variant, remainingBalance As Integer) As Date
'* Note:
'*
'* replace query1 with the name of your first query
'* replace all column name with correct column name from query1
'*
'* replace query1 with the name of your second query
'*
Dim totalOut As Integer
Dim rs As DAO.Recordset
If db Is Nothing Then Set db = CurrentDb
'* open recordset from query1 with only relevant partNumber
Set rs = db.OpenRecordset("select [usage date], [usage qty] from query1 " & _
"where [part number]=" & Chr(34) & partNumber & Chr(34) & " " & _
"order by [usage date] asc", _
dbOpenSnapshot)
'* get the inventory quantity from query2
totalOut = DLookup("[on hand inventory]", "query2", "[part number]=" & Chr(34) & partNumber & Chr(34))
'* arbitrary value
fnStockOutDate = Date
With rs
If Not (.BOF And .EOF) Then .MoveFirst
Do While Not .EOF
totalOut = totalOut - ![usage qty]
.MoveNext
If totalOut <= 0 Then
Exit Do
End If
Loop
If Not .EOF Then fnStockOutDate = ![usage date]
.Close
End With
Set rs = Nothing
End Function
Usage Query
Item. Usage date. Qty. used
548-542 4/6/2018 1
548-542 4/16/2018 2
548-542 4/24/2018 1
548-542 5/2/2018 1
548-542 5/10/2018 1
548-542 5/18/2018 1
548-542 5/25/2018 1
645-214 4/9/2018 2
645-214 5/4/2018 2
645-214 5/8/2018 1
645-214 5/23/2018 2
645-214 6/21/2018 2
645-214 7/6/2018 1
CurrentInv Query
Item. Current Qty.
548-542 5
645-214 4
DeliveryInv Query
ITEM PLANDELDATE ORDQTY
548-542 4/14/2018 3
645-214 4/25/2018 4
Last edited: