When I try to utilize this function in a query, I get a syntax error. I've looked and I can't pinpoint it. Can somebody point it out?
In the query: RunBal: fncRunBal([ITEM_ID],[QTY],[PierceBal])
Function fncRunBal(strItemId As String, lngQty As Long, lngPierceBal As Long) As Long
'Variables that retain their values.
Static strPartNo As String 'This is the Part Number (strItemId)'
Static lngNeed As Long 'This is the s/o quantity (lnqQty)'
Static lngBal As Long 'This is the running sum of what is required to fab (lngPierceBal)'
If strPartNo <> strItemId Then 'If the current ID does not match the last ID, then (re)initialize.
strPartNo = strItemId 'Reset the part number to the new part number'
lngNeed = lngQty 'Reset the s/o quantity'
lngBal = lngPierceBal 'Reset the PierceBal'
If lngBal <= 0 Then 'If the 1st PierceBal record of the new part number is <= 0'
lngRun = Abs(lngBal) 'Then run the absolute value of PierceBal'
Else
lngRun = 0 'If positive, don't run any'
End If
Else 'If the current ID matches the last and the PierceBal is negative show the s/o quantity'
If lngBal <= 0 Then 'If PierceBal is negative'
lngRun = lngNeed 'Run the s/o qty'
Else 'If PierceBal is positive'
lngRun = 0 'Don't run any'
End If
End If
'Pass the balance to run back to the query.
fncRunBal = lngRun
End Function
In the query: RunBal: fncRunBal([ITEM_ID],[QTY],[PierceBal])
Function fncRunBal(strItemId As String, lngQty As Long, lngPierceBal As Long) As Long
'Variables that retain their values.
Static strPartNo As String 'This is the Part Number (strItemId)'
Static lngNeed As Long 'This is the s/o quantity (lnqQty)'
Static lngBal As Long 'This is the running sum of what is required to fab (lngPierceBal)'
If strPartNo <> strItemId Then 'If the current ID does not match the last ID, then (re)initialize.
strPartNo = strItemId 'Reset the part number to the new part number'
lngNeed = lngQty 'Reset the s/o quantity'
lngBal = lngPierceBal 'Reset the PierceBal'
If lngBal <= 0 Then 'If the 1st PierceBal record of the new part number is <= 0'
lngRun = Abs(lngBal) 'Then run the absolute value of PierceBal'
Else
lngRun = 0 'If positive, don't run any'
End If
Else 'If the current ID matches the last and the PierceBal is negative show the s/o quantity'
If lngBal <= 0 Then 'If PierceBal is negative'
lngRun = lngNeed 'Run the s/o qty'
Else 'If PierceBal is positive'
lngRun = 0 'Don't run any'
End If
End If
'Pass the balance to run back to the query.
fncRunBal = lngRun
End Function
Last edited: