EXCEL(VBA)~SQL 经典写法范本汇集(二)
时 间:2012-04-07 09:09:03
作 者:欢乐小爪 ID:20149 城市:杭州
摘 要:EXCEL(VBA)~SQL 经典写法范本汇集(二)
正 文:
一)
选择供应商和选择月份记录的查询
原创:小爪 日期:2008-5-10
Private Sub CommandButton1_Click()
Range("a5:k1000").ClearContents
Set conn = CreateObject("ADODB.Connection")
conn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;imex=1';data source=" & ThisWorkbook.FullName
If Range("b3") = "全部" And Range("d3") = "全部" Then
Sql = "select * from [数据源$a3:i1000] "
GoTo 100
End If
If Range("b3") = "全部" Then
'
Sql = "select * from [数据源$a3:i1000] where month(日期) = '" & [d3] & "'"
GoTo 100
End If
If Range("d3") = "全部" Then
Sql = "select * from [数据源$a3:i1000] where 供应商= '" & [b3] & "'"
GoTo 100
End If
If Range("d3") <> "全部" And Range("d3") <> "全部" Then
i = Range("d3")
Sql = "select * from [数据源$a3:i1000] where (供应商= '" & [b3] & "') and (month(日期) = '" & i & "')"
GoTo 100
End If
100:
Sheets("统计").Range("a5").CopyFromRecordset conn.Execute(Sql)
conn.Close: Set conn = Nothing
End Sub
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
二)查询某地的 收款记录工作表 的收款日期,凭证号,金额,摘要
和 送货记录工作表 的发货日期,单号,金额,折扣,赠送,退货,备注
原创:小爪 日期:2008-5-6
实例地址:E:\欢乐--office\小爪-excel\小爪-vba\ADO+SQL
Private Sub CommandButton1_Click()
Range("a6:k16").ClearContents
Set conn = CreateObject("ADODB.Connection")
conn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;imex=1';data source=" & ThisWorkbook.FullName
Sql1 = "select 收款日期,凭证号,金额,摘要 from [收款记录$B2:F20] where 客户名称 = '" & [b2] & "'"
Sql2 = "select 发货日期,单号,金额,折扣,赠送,退货,备注 from [送货记录$B2:i20] where 客户名称 = '" & [b2] & "'"
Sheets("套打").Range("a6").CopyFromRecordset conn.Execute(Sql1)
Sheets("套打").Range("e6").CopyFromRecordset conn.Execute(Sql2)
conn.Close: Set conn = Nothing
End Sub
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 【Access选项卡示例】Ac...(09.09)
- 【Access源码示例】按输入...(09.02)
- 【Access日期区间段查询】...(08.29)
- 【Access日期区间段查询】...(08.27)
- Access怎样才能实现日期时...(08.21)
- 【Access定时打开查询】A...(08.19)
- Access生成固定数量的记录...(08.13)
- Access怎样才能实现日期时...(08.12)
- Access利用导航窗体控件对...(08.03)
学习心得
最新文章
- Access表中的字段名、字段标题...(09.19)
- Access快速开发平台--更改“...(09.18)
- 【中秋及国庆优惠】Access培训...(09.15)
- Access如何将日期型的数值转换...(09.14)
- 英文输入法输入数据中存在单引号引起...(09.11)
- 【Access选项卡示例】Acce...(09.09)
- 让Access光标停留在指定的控件...(09.07)
- 关于Access查询条件里使用通配...(09.06)
- Access报表偷懒制作法--Ac...(09.05)
- Access快速开发平台--窗体数...(09.04)