|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
<P>例:</P>
<P> ListView5.ListItems.Clear<BR> SQL = "Select 销售清单号,销售数量,销售金额,销售成本 from XSD where 商品编码='" & Item.SubItems(1) & "' AND MID(销售清单号,3,8)>= " & CStr(TextBox1.Text) & " and mid(销售清单号,3,8)<= " & CStr(TextBox2.Text)<BR> RST.Open SQL, CNN, adOpenKeyset, adLockOptimistic<BR> hj1 = 0<BR> hj2 = 0<BR> hj3 = 0<BR> hj4 = 0<BR> For i = 1 To RST.RecordCount<BR> With ListView5.ListItems.Add(, , RST.Fields("销售清单号"))<BR> .SubItems(1) = IIf(IsNull(RST.Fields("销售数量")), 0, RST.Fields("销售数量"))<BR> .SubItems(2) = IIf(IsNull(RST.Fields("销售金额")), 0, Format(RST.Fields("销售金额"), "0.00"))<BR> .SubItems(3) = IIf(IsNull(RST.Fields("销售成本")), 0, Format(RST.Fields("销售成本"), "0.00"))<BR> .SubItems(4) = Format(CDbl(ListView5.ListItems(i).SubItems(2)) - CDbl(ListView5.ListItems(i).SubItems(3)), "0.00")<BR> hj1 = hj1 + .SubItems(1)<BR> hj2 = hj2 + .SubItems(2)<BR> hj3 = hj3 + .SubItems(3)<BR> hj4 = hj4 + .SubItems(4)<BR> End With<BR> RST.MoveNext<BR> Next i<BR> With ListView5.ListItems.Add(, , "合计")<BR> .SubItems(1) = IIf(IsNull(hj1), 0, hj1)<BR> .SubItems(2) = IIf(IsNull(hj2), 0, hj2)<BR> .SubItems(3) = IIf(IsNull(hj3), 0, hj3)<BR> .SubItems(4) = IIf(IsNull(hj4), 0, hj4)<BR> End With<BR> RST.Close</P> |
|