|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
jaychen007 发表于 2012-10-18 15:31
大哥您好,真的十分感谢你,你帮我看看这个问题好吗,这个问题对您来说一定是很简单的。说明都在我的附件 ... - Sub 查询()
- Dim cnn As Object
- Dim SQL$, s$
- Dim arr, brr, i&
- Set cnn = CreateObject("ADODB.Connection")
- SQL = "select * from Tabell"
- arr = Range("C2:E3")
- brr = Array("", "'", "'", "'")
- For i = 1 To UBound(arr, 2)
- If Len(arr(2, i)) Then s = s & " and " & arr(1, i) & "=" & brr(i) & arr(2, i) & brr(i)
- Next
- If Len(s) Then SQL = SQL & " where " & Mid(s, 6)
- cnn.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.Path & "\inn og ut.mdb"
- ActiveSheet.UsedRange.Offset(7).ClearContents
- [a8].CopyFromRecordset cnn.Execute(SQL)
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码 |
|