|
在本坛里找了个文件。可以不能模糊查询。麻烦好心人帮忙修改一下。
Sub 查询()
'引用Microsoft ActiveX Data Objects 2.x Library
Dim cnn As New ADODB.Connection
Dim SQL$, arr, i&, s$
arr = Range("D1").CurrentRegion
If Not IsArray(arr) Then Exit Sub
If UBound(arr) = 1 Then Exit Sub
If Len(arr(2, 1)) Then s = s & " and " & arr(1, 1) & "=" & arr(2, 1)
For i = 2 To UBound(arr, 2)
If Len(arr(2, i)) Then s = s & " and " & arr(1, i) & "='" & arr(2, i) & "'"
Next
SQL = "select * from 账户资料 where" & Mid(s, 5)
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\查询修改ac.accdb"
Range("D6:O" & Rows.Count).ClearContents
Range("d6").CopyFromRecordset cnn.Execute(SQL)
cnn.Close
Set cnn = Nothing
End Sub |
|