|
原帖由 望江婷 于 2011-3-12 09:47 发表
你好赵老师,我将分类汇总的结果在加了个汇总小计,代码不对呢,烦劳赵老师看看,谢谢
886942
Private Sub CommandButton19_Click()
Dim i%, arr, sql As String
For i = 1 To 4
If Len(Controls("ComboBox" & i).Value) Then s = s & " and " & Controls("Label" & i).Caption & "='" & Controls("ComboBox" & i).Value & "'"
Next
If s = "" Then Exit Sub
sql1 = "select 年份,null,项目名称,施工单位,费用类别,费用明细,sum(金额) from 费用汇总单 where " & Mid(s, 6) & " group by 年份,项目名称,施工单位,费用类别,费用明细"
'--------------------------------下面这句求和怎么写呢?
' sql2 = sql1 & " '小计',null,null,null,null,null,sum(金额)from 费用汇总单"
sql2 = "select '小计',null,null,null,null,null,sum(金额) from 费用汇总单 where " & Mid(s, 6)
'-----------------------------------------------------
sql = sql1 & " union all " & sql2
Sheets("查询").[a3:h65536] = ""
Sheets("查询").[b3].CopyFromRecordset cnn.Execute(sql)
End Sub |
|