代码放在按键事件里面,统计出来结果不是指定日期,还是统计出来很多个月,把筛选代码放前面的,统计代码放后面
Dim Filter As String
With e.Form.Controls("StartDate")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "输入日期 >= #" & .Value & "#"
End If
End With
With e.Form.Controls("EndDate")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "输入日期 <= #" & .Value & "#"
End If
End With
If Filter > "" Then
Tables("计件统计").Filter = Filter
End If
Dim bd1 As New GroupTableBuilder("统计表1", DataTables("计件统计"))
Dim dt1 As fxDataSource
bd1.Groups.AddDef("姓名") '根据型号分组
bd1.Totals.AddDef("数量", "数量") '对数量进行统计
bd1.Totals.AddDef("金额", "金额") '对金额进行统计
dt1 = bd1.BuildDataSource()
Dim bd2 As New GroupTableBuilder("统计表2", DataTables("计件统计"))
Dim dt2 As fxDataSource
bd2.Groups.AddDef("姓名1") '根据型号分组
bd2.Totals.AddDef("数量1", "数量") '对数量进行统计
bd2.Totals.AddDef("金额1", "金额") '对金额进行统计
dt2 = bd2.BuildDataSource()
Dim bd3 As New GroupTableBuilder("统计表3", DataTables("计件统计"))
Dim dt3 As fxDataSource
bd3.Groups.AddDef("姓名2") '根据型号分组
bd3.Totals.AddDef("数量2", "数量") '对数量进行统计
bd3.Totals.AddDef("金额2", "金额") '对金额进行统计
dt3 = bd3.BuildDataSource()
Dim bd4 As New GroupTableBuilder("统计表4", DataTables("计件统计"))
Dim dt4 As fxDataSource
bd4.Groups.AddDef("姓名3") '根据型号分组
bd4.Totals.AddDef("数量3", "数量") '对数量进行统计
bd4.Totals.AddDef("金额3", "金额") '对金额进行统计
dt4 = bd4.BuildDataSource()
Dim bd5 As New GroupTableBuilder("统计表5", DataTables("计件统计"))
Dim dt5 As fxDataSource
bd5.Groups.AddDef("姓名4") '根据型号分组
bd5.Totals.AddDef("数量4", "数量") '对数量进行统计
bd5.Totals.AddDef("金额4", "金额") '对金额进行统计
dt5 = bd5.BuildDataSource()
Dim bd6 As New GroupTableBuilder("统计表6", DataTables("计件统计"))
Dim dt6 As fxDataSource
bd6.Groups.AddDef("姓名5") '根据型号分组
bd6.Totals.AddDef("数量5", "数量") '对数量进行统计
bd6.Totals.AddDef("金额5", "金额") '对金额进行统计
dt6 = bd6.BuildDataSource()
dt1.Combine("姓名", dt2, "姓名1") '将销售统计数据组合到进货统计数据
dt1.Combine("姓名", dt3, "姓名2") '将退货统计数据组合到进货统计数据
dt1.Combine("姓名", dt4, "姓名3") '将销售统计数据组合到进货统计数据
dt1.Combine("姓名", dt5, "姓名4") '将退货统计数据组合到进货统计数据
dt1.Combine("姓名", dt6, "姓名5") '将退货统计数据组合到进货统计数据
Tables("汇总窗_Table1").DataSource = dt1 '将统计结果绑定到Table
With DataTables("汇总窗_Table1").DataCols '用表达式列计算库存数据
.Add("合计数量", GetType(Integer), "IsNull([数量],0) + ISNULL([数量1],0) + ISNULL([数量2],0)+IsNull([数量3],0) + ISNULL([数量4],0) + ISNULL([数量5],0)")
.Add("合计金额", GetType(Double), "IsNull([金额],0) + ISNULL([金额1],0) + ISNULL([金额2],0)+IsNull([金额3],0) + ISNULL([金额4],0) + ISNULL([金额5],0)")
End With
此主题相关图片如下:统计截图.png