:banghead::banghead::banghead:
Hi everyone,
This is my first post here. I am trying for 2 days now to create a module that will make FIFO calculation in my APP.
I am using 2 queries to pull the data.
1) zFifoExOst - The query that holds all my sales
2) zFifoObOst - The query that holds all my purchase
each variable starting with "e" has to do with sale
each variable starting with "o" has to do with purchase
The problem is that when my Sale Quantity is greater than my Purchase i am getting a loop over same record over and over.
I am not a profy in vba programming so it can be something stupid.
Anyway thanks in advance.
The code:
Hi everyone,
This is my first post here. I am trying for 2 days now to create a module that will make FIFO calculation in my APP.
I am using 2 queries to pull the data.
1) zFifoExOst - The query that holds all my sales
2) zFifoObOst - The query that holds all my purchase
each variable starting with "e" has to do with sale
each variable starting with "o" has to do with purchase
The problem is that when my Sale Quantity is greater than my Purchase i am getting a loop over same record over and over.
I am not a profy in vba programming so it can be something stupid.
Anyway thanks in advance.
The code:
Code:
Option Compare Database
Option Explicit
Public eProductID As Long
Public eRecID As Long
Public eQty As Double
Public eParty As Long
Public eDate As Date
Public oRecId As Long
Public oQty As Double
Public oParty As Long
Public oDate As Long
Public eQtyLeft As Double
Public eQtyCounted As Double
Public oQtyLeft As Double
Public Row As Long
Public Function GetIDFIFO()
GetIDFIFO = eProductID
End Function
Public Sub FIFOloop()
Row = 0
eQtyLeft = 0
eQtyCounted = 0
oQtyLeft = 0
Dim FIFOexpend As Recordset
Set FIFOexpend = CurrentDb.OpenRecordset("zFifoExOst ")
If FIFOexpend.RecordCount <> 0 Then
FIFOexpend.MoveLast
FIFOexpend.MoveFirst
Do While Not FIFOexpend.EOF
eProductID = FIFOexpend.Fields("GoodsID")
eRecID = FIFOexpend.Fields("ExpendGoodsID")
eQty = FIFOexpend.Fields("CountUnits") - eQtyCounted
eParty = FIFOexpend.Fields("KodParty")
eDate = FIFOexpend.Fields("DateExpend")
Dim FIFOobtain As Recordset
Set FIFOobtain = CurrentDb.OpenRecordset("zFifoObOst ")
If FIFOobtain.RecordCount <> 0 Then
FIFOobtain.MoveLast
FIFOobtain.MoveFirst
oRecId = FIFOobtain.Fields("GoodsID")
oQty = FIFOobtain.Fields("CountUnits")
oParty = FIFOobtain.Fields("KodParty")
oDate = FIFOobtain.Fields("DateExpend")
If oQty >= eQty Then
'Add to rst
oQtyLeft = oQty - eQty
eQtyLeft = 0
eQtyCounted = 0
Row = Row + 1
'Update the obtain
'Debug.Print "OstOb: " & oQtyLeft & "Row: " & Row
ElseIf oQty < eQty Then
'Debug.Print "Expend Greater" & "Row: " & Row
oQtyLeft = 0
eQtyLeft = eQty - oQty
eQtyCounted = eQty - eQtyLeft
Row = Row + 1
End If
Else
MsgBox ("Obtain Missing for the Expend Record " & eRecID)
GoTo LastLine
End If
FIFOobtain.Close
If eQtyLeft = 0 Then
FIFOexpend.MoveNext
[B][COLOR="Red"] ElseIf eQtyLeft > 0 Then[/COLOR][/B]
FIFOexpend.MoveNext
FIFOexpend.MovePrevious
End If
Debug.Print "Row: " & Row; " Good : " & eProductID; " Expend ID: " & eRecID & " Obtain ID: " & oRecId
Loop
End If
LastLine:
FIFOexpend.Close
Set FIFOexpend = Nothing
Set FIFOobtain = Nothing
eProductID = 0
eRecID = 0
eQty = 0
eParty = 0
eDate = 0
oRecId = 0
oQty = 0
oParty = 0
oDate = 0
End Sub
Last edited: