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高效办公】统计当...(06.30)
- 【Access高效办公】用复选...(06.24)
- 根据变化的日期来自动编号的示例...(06.20)
- 【Access高效办公】按日期...(06.12)
- 合并列数据到一个文本框的示例;...(05.06)
- 通过命令按钮让Access列表...(04.24)
- 【Access高效办公】统计当...(03.11)
- 【Access Inputbo...(03.03)
- 按回车键后光标移动到下一条记录...(02.12)

学习心得
最新文章
- 关于Access交叉表查询生成的统...(08.02)
- ACCESS做的工作日常小工具_纸...(07.30)
- Access快速开发平台进销存教程...(07.28)
- 关于Access快速开发平台2.6...(07.23)
- 【Access交叉表查询】按百分比...(07.21)
- VBA编程-ADO-关于对象早晚期...(07.17)
- Access快速开发平台--frm...(07.15)
- 1行代码实现Access与SQL ...(07.09)
- 免费《仓库管理实战课程》全集(07.08)
- Access快速开发平台--Win...(07.07)