G
Guest
I am new to writing functions and subs. I have been using access for 7 years
and have pretty much always found a solution for data analysis via queries,
but now I have a situation that I can't get a simple query to handle.
I need to call a function with 3 paramaters (vpart_id, vBeg_Date, vEnd_Date)
lets call it GetInvOuts that returns one numeric value.
From the function I need to get the sum of a field called QTY from a table
called INV_TRANS where the PART_ID = vpart_id and the TRANSACTION DATE >=
vBeg_Date and TRANSACTION_DATE <= vEnd_Date)
Any help is greatly appreciated.
This is what i have tried so far and I am getting no values in the query.
Public Function GetInvOuts(vPartID As String, vBeginDate As Date, vEndDate
As Date)
On Error Resume Next
Dim sqlStr As String
sqlStr = "SELECT SYSADM_INVENTORY_TRANS.PART_ID,
Sum(SYSADM_INVENTORY_TRANS.QTY) AS SumOfQTY" & _
" FROM SYSADM_INVENTORY_TRANS" & _
" WHERE (((SYSADM_INVENTORY_TRANS.TRANSACTION_DATE) Between
vBeginDate And vEndDate) AND ((SYSADM_INVENTORY_TRANS.TYPE)='O'))" & _
" GROUP BY SYSADM_INVENTORY_TRANS.PART_ID" & _
" HAVING (((SYSADM_INVENTORY_TRANS.PART_ID)=vPartID))"
DoCmd.RunSQL sqlStr
GetInvOuts = SumOfQty
End Function
Brent Fanguy
and have pretty much always found a solution for data analysis via queries,
but now I have a situation that I can't get a simple query to handle.
I need to call a function with 3 paramaters (vpart_id, vBeg_Date, vEnd_Date)
lets call it GetInvOuts that returns one numeric value.
From the function I need to get the sum of a field called QTY from a table
called INV_TRANS where the PART_ID = vpart_id and the TRANSACTION DATE >=
vBeg_Date and TRANSACTION_DATE <= vEnd_Date)
Any help is greatly appreciated.
This is what i have tried so far and I am getting no values in the query.
Public Function GetInvOuts(vPartID As String, vBeginDate As Date, vEndDate
As Date)
On Error Resume Next
Dim sqlStr As String
sqlStr = "SELECT SYSADM_INVENTORY_TRANS.PART_ID,
Sum(SYSADM_INVENTORY_TRANS.QTY) AS SumOfQTY" & _
" FROM SYSADM_INVENTORY_TRANS" & _
" WHERE (((SYSADM_INVENTORY_TRANS.TRANSACTION_DATE) Between
vBeginDate And vEndDate) AND ((SYSADM_INVENTORY_TRANS.TYPE)='O'))" & _
" GROUP BY SYSADM_INVENTORY_TRANS.PART_ID" & _
" HAVING (((SYSADM_INVENTORY_TRANS.PART_ID)=vPartID))"
DoCmd.RunSQL sqlStr
GetInvOuts = SumOfQty
End Function
Brent Fanguy