|
下面的上期数据是根据月进行计算的,我想改成日,请高手帮帮忙啦
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 原料.产品编号, Sum(([进货]-[出货])) AS 库存 " & _
"FROM 原料 " & _
"WHERE 原料.[rq] < #" & lngM & "/1" & "/" & lngY & "# And 产品编号 ='" & strCodeID & "' " & _
"GROUP BY 原料.产品编号;"
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 |
|