实例18:用 Union 从字段不相同的两个 Access 表中筛选记录后按相似字段排序: http://club.excelhome.net/viewthread.php?tid=196804&replyID=574405&skin=0 CNN.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & ThisWorkbook.Path & "\sales.mdb" SQL = "SELECT 年,月,日,发货单号,产品名称,规格,数量,单位,金额 as 销售金额,'' as 回款金额 FROM sale " & _ " WHERE (((CDate([月] & '-' & [日] & '-' & [年])) Between #" & CDate(TextBox1.Text) & "# And #" & CDate(TextBox2.Text) & "#)) " & _ "and 发货单号 not like '%★%' and 客户名称 like '%" & TextBox3.Text & "%' " & _ "UNION ALL SELECT nian as 年,yue as 月,ri as 日,'' as 发货单号,con as 产品名称,'' as 规格,'' as 数量,'' as 单位,'' as 销售金额,je as 回款金额 FROM skd " & _ "WHERE khmc like '%" & TextBox3.Text & "%' " & _ "AND (((CDate([yue] & '-' & [ri] & '-' & [nian])) Between #" & CDate(TextBox1.Text) & "# And #" & CDate(TextBox2.Text) & "#)) ORDER BY 年,月,日,发货单号" RST.Open SQL, CNN, adOpenKeyset, adLockOptimistic Do Until RST.EOF With ListView1.ListItems.Add(, , RST.Fields("年")) .SubItems(1) = RST.Fields("月") .SubItems(2) = RST.Fields("日") .SubItems(3) = RST.Fields("发货单号") .SubItems(4) = IIf(RST.Fields("产品名称") = "收到货款", "收到货款", RST.Fields("产品名称") & RST.Fields("规格") & " " & RST.Fields("数量") & RST.Fields("单位")) .SubItems(5) = Format(RST.Fields("销售金额"), "#,##0.00") .SubItems(6) = Format(RST.Fields("回款金额"), "#,##0.00") xsje = GetxsjeSum(ListView1.ListItems.Count) hkje = GethkjeSum(ListView1.ListItems.Count) .SubItems(7) = Format(qcje + xsje - hkje, "#,##0.00") RST.MoveNext End With Loop RST.Close With ListView1.ListItems.Add .SubItems(4) = " 本 月 合 计" .SubItems(5) = IIf(IsNull(xsje), "", Format(xsje, "#,##0.00")) .SubItems(6) = IIf(IsNull(hkje), "", Format(hkje, "#,##0.00")) End With Set CNN = Nothing
gZkSsJOO.rar
(117.45 KB, 下载次数: 204)
UINON 的另一个例子及解说: http://club.excelhome.net/dispbbs.asp?boardid=2&replyid=624979&id=205529&page=1&skin=0&Star=2 第 12 楼
[此贴子已经被作者于2006-12-18 18:04:41编辑过] |