|
2#
楼主 |
发表于 2006-3-23 23:51:00
|
只看该作者
Private Sub 计算下月期初_Click()
Dim tixing As String
tixing = MsgBox(" 真得要结转" & Me.结转月份.Value + "的月末库存到下月期初吗?", 1, "警告")
If tixing = 1 Then
Dim st最后年月 As String
Dim st下月年月 As String
Dim stsql As String
st最后年月 = DMax("年月", "产品期初期末")
If Mid(st最后年月, 6, 2) = "12" Then
st下月年月 = Val(Left(st最后年月, 4)) + 1 & "年01月"
Else
st下月年月 = Left(st最后年月, 4) & "年" & Right("0" & (Val(Mid(st最后年月, 6, 2)) + 1), 2) & "月"
End If
stsql = "SELECT Year(进货日期) & '年' & Month(进货日期) & '月' AS 年月, " & _
"产品ID, Sum(进货.数量) AS 数量 " & _
"FROM 进货 " & _
"WHERE (Year(进货日期) & '年' & Format(进货日期,'mm') & '月')='" & st最后年月 & "' " & _
"GROUP BY Year(进货日期) & '年' & Month(进货日期) & '月', 产品ID "
CurrentDb.QueryDefs("查询月合计_进货").SQL = stsql
stsql = "SELECT Year(服务日期) & '年' & Month(服务日期) & '月' AS 年月, " & _
"产品ID, Sum(发票.数量) AS 数量 " & _
"FROM 查询_发票 " & _
"WHERE (Year(服务日期) & '年' & Format(服务日期,'mm') & '月')='" & st最后年月 & "' " & _
"GROUP BY Year(服务日期) & '年' & Month(服务日期) & '月', 产品ID "
CurrentDb.QueryDefs("查询月合计_发票").SQL = stsql
stsql = "SELECT Year(盘查日期) & '年' & Month(盘查日期) & '月' AS 年月, " & _
"产品ID, Sum(产品盘盈盘亏.数量) AS 数量 " & _
"FROM 产品盘盈盘亏 " & _
"WHERE (Year(盘查日期) & '年' & Format(盘查日期,'mm') & '月')='" & st最后年月 & "' " & _
"GROUP BY Year(盘查日期) & '年' & Month(盘查日期) & '月', 产品ID "
CurrentDb.QueryDefs("查询月合计_盈亏").SQL = stsql
stsql = "SELECT '" & st下月年月 & "' AS 年月, 查询月合计_变化量.产品ID,查询月合计_变化量.产品名称, 查询月期初数量.期初数量+[变化量] AS 期初数量 " & _
"FROM 查询月合计_变化量 LEFT JOIN 查询月期初数量 ON 查询月合计_变化量.产品ID = 查询月期初数量.产品ID"
CurrentDb.QueryDefs("查询月合计_下月期初").SQL = stsql
stsql = "SELECT * FROM 产品期初期末 WHERE 年月='" & st最后年月 & "'"
CurrentDb.QueryDefs("查询月期初数量").SQL = stsql
stsql = "INSERT INTO 产品期初期末 ( 年月, 产品ID,产品名称, 期初数量 ) " & _
"SELECT 查询月合计_下月期初.年月, 查询月合计_下月期初.产品ID,查询月合计_下月期初.产品名称, 查询月合计_下月期初.期初数量 " & _
"FROM 查询月合计_下月期初"
DoCmd.RunSQL stsql
Me.Refresh
End If |
|