|
Public Function k(strCodeID As String, lngY As Long, lngM As Long) As Long
Dim strSQL As String
Dim rs As Object
Dim cn As Object
Set cn = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.Recordset")
'
strSQL = "SELECT 材料收支表.材料ID, Sum(([进库]-[出库])) AS 库存 " & _
"FROM 材料收支表 " & _
"WHERE 材料收支表.日期 < #" & lngM & "/1" & "/" & lngY & "# And 材料ID ='" & strCodeID & "' " & _
"GROUP BY 材料收支表.材料ID;"
rs.Open strSQL, cn, 1
If rs.EOF = True Then Exit Function
k = rs("库存")
'MsgBox k
rs.Close
Set rs = Nothing
Set cn = Nothing
End Function |
|