|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 yuanlinfj 于 2012-11-21 15:26 编辑
Sub 查询()
Dim cnn As Object
Dim SQL$, s$
Dim arr, brr, i&
Set cnn = CreateObject("ADODB.Connection")
SQL = "select * from 计划表 "
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 & "\mrp.mdb"
ActiveSheet.UsedRange.Offset(7).ClearContents
[a8].CopyFromRecordset cnn.Execute(SQL)
cnn.Close
Set cnn = Nothing
End Sub
查出来的结果没有顺序性 本人试过加 order by id ASC 来控制 ,但整体查找顺序有了,却影响精确查找过程!,应该如何解决?? |
|