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
With e.Form.Controls("C1")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "客户 = '" & .Value & "'"
End If
End With
With e.Form.Controls("C2")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "品名 = '" & .Value & "'"
End If
End With
With e.Form.Controls("C3")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "规格 = '" & .Value & "'"
End If
End With
Dim b As New GroupTableBuilder("统计表1", DataTables("订单明细")) '
b.Groups.AddDef("客户") '
b.Groups.AddDef("品名")
b.Groups.AddDef("规格")
b.Totals.AddDef("数量","订购数量") '
b.Totals.AddDef("金额","订购金额") '
b.Filter = Filter
Tables("订单统计窗口_Table1").DataSource = b.BuildDataSource()
以上代码,是客户、品名、规格、时间的分组进行统计,如果分成多个分组统计如下面几种,就是分多的按键来实现。
如何实现一个按键多种分组统计?
1.分组一,以客户和品名进行统计,以复重的客户名称合并后进行显示
Dim b As New GroupTableBuilder("统计表1", DataTables("订单明细")) '
b.Groups.AddDef("客户") '
b.Groups.AddDef("品名")
b.Totals.AddDef("数量","订购数量") '
b.Totals.AddDef("金额","订购金额") '
b.Filter = Filter
Tables("订单统计窗口_Table1").DataSource = b.BuildDataSource()
2.分组二,以客户和规格进行统计,以复重的客户名称合并后进行显示
Dim b As New GroupTableBuilder("统计表1", DataTables("订单明细")) '
b.Groups.AddDef("客户") '
b.Groups.AddDef("规格")
b.Totals.AddDef("数量","订购数量") '
b.Totals.AddDef("金额","订购金额") '
b.Filter = Filter
Tables("订单统计窗口_Table1").DataSource = b.BuildDataSource()
3.分组三,以客户、品名、规格进行统计,以复重的客户名称和品名合并后进行显示
Dim b As New GroupTableBuilder("统计表1", DataTables("订单明细")) '
b.Groups.AddDef("客户") '
b.Groups.AddDef("品名")
b.Groups.AddDef("规格")
b.Totals.AddDef("数量","订购数量") '
b.Totals.AddDef("金额","订购金额") '
b.Filter = Filter
Tables("订单统计窗口_Table1").DataSource = b.BuildDataSource()
4.分组4,规格进行统计
Dim b As New GroupTableBuilder("统计表1", DataTables("订单明细")) '
b.Groups.AddDef("规格")
b.Totals.AddDef("数量","订购数量") '
b.Totals.AddDef("金额","订购金额") '
b.Filter = Filter
Tables("订单统计窗口_Table1").DataSource = b.BuildDataSource()
[此贴子已经被作者于2023/5/5 14:58:55编辑过]