[英]How to use VBA to Get result from an Access fuzzy query?
Database just like 数据库就像
In Access query design I use 在Access查询设计中,我使用
select * from dbname where name like '*'& [The Name ?] &'*'
to do the fuzzy search, it works all right. 做模糊搜索,就可以了。
But when I use this query in VBA ,it's just get nothing back. 但是,当我在VBA中使用此查询时,什么也收不到。
Public Sub SeekClientData()
Dim adoConn As ADODB.Connection
Dim adoRs As ADODB.Recordset
Set adoConn = New ADODB.Connection
Set adoRs = New ADODB.Recordset
With adoConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open ThisWorkbook.Path & "\fsdb.mdb"
End With
adoRs.Open "[testquery]'aa'", adoConn 'testQuery
Range("A2").CopyFromRecordset adoRs
adoRs.Close: Set adoRs = Nothing
adoConn.Close: Set adoConn = Nothing
End Sub
When I debug this code, I just get adoRs.EOF. 当我调试此代码时,我只得到adoRs.EOF。
But When I set it strict, I mean no fuzzy, It works all right. 但是当我设定严格的时候,我的意思是不会模糊,它可以正常工作。 I mean this: 我的意思是:
select * from dbname where name=[The Name ?]
works right. 工作正常。
I have done a lot search, but can't solve this.Any help is welcome! 我已经做了很多搜索,但无法解决这个问题。欢迎任何帮助!
Range(A2)? 范围(A2)? Sounds like Excel. 听起来像Excel。 ThisWorkbook.Path also sounds like Excel. ThisWorkbook.Path听起来也像Excel。 Is this strictly in Access? 这严格在Access中吗? Is it a hybrid? 它是混合动力车吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.