|
'说明:要求在月底汇总信息表当前月份中的内容,日期生成下月的1号,下述代码在access2000测试通过
Private Sub 命令_Click()
On Error GoTo 0
If CurrentData.AllTables!信息表.IsLoaded = True Then
DoCmd.Close acTable, "信息表"
End If '在汇总之前如果信息表打开则关闭信息表
Dim rs As ADODB.Recordset
Dim rsa As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "select 名称,sum(入库) as 入库,month(日期) as 日期 from 信息表 group by 名称, month(日期) having month(日期)=month(now())", _
CurrentProject.Connection, adOpenKeyset, adLockOptimistic '使用查询打开打开当前月份汇总记录集
If rs.EOF Then '如果查询内容为空,退出过程
MsgBox "信息表中当前月份没有记录"
Exit Sub
End If
Set rsa = New ADODB.Recordset
rsa.Open "select 名称,入库,日期 from 信息表", CurrentProject.Connection, adOpenKeyset, adLockOptimistic '打开信息表记录集
Do Until rs.EOF
rsa.AddNew
rsa!名称 = rs!名称 & Month(Now()) & "月汇总"
rsa!入库 = rs!入库
rsa!日期 = CDate(Year(Now()) & "-" & Month(Now()) + 1 & "-1")
rs.MoveNext
Loop
MsgBox "信息表中" & Month(Now()) & "月份内容汇总成功!"
Set rsa = Nothing
Set rs = Nothing
0:
End Sub
|
|