Excel怎么用VBA实现根据一个单元格内容从access数据库搜索数据并返回Excel中相应单元格?
展开全部
Sub 查找()
Set conn = CreateObject("adodb.connection")
Set Rst = CreateObject("ADODB.recordset")
conn.Open
"答差汪Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
& "D:/Database.accdb" ''后面是数据库路径 自己修改,看上去是07版本的,如果是03版本的将庆正前面的字符串换成 "provider=Microsoft.jet.OLEDB.4.0;data source="
WITH Rst
.Open "select * from 基站信息 where 地点清仔='" & [b3] & "'", conn, adOpenKeyset, adLockOptimistic
If .RecordCount >0 Then
[B4]=.FIELDS("经度")
[B5]=.FIELDS("纬度")
[B6]=.FIELDS("PROVINCE")
ELSE: MsgBox "找不到该名称"
End If
end with
conn.Close
Set conn = Nothing
End Sub
Set conn = CreateObject("adodb.connection")
Set Rst = CreateObject("ADODB.recordset")
conn.Open
"答差汪Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
& "D:/Database.accdb" ''后面是数据库路径 自己修改,看上去是07版本的,如果是03版本的将庆正前面的字符串换成 "provider=Microsoft.jet.OLEDB.4.0;data source="
WITH Rst
.Open "select * from 基站信息 where 地点清仔='" & [b3] & "'", conn, adOpenKeyset, adLockOptimistic
If .RecordCount >0 Then
[B4]=.FIELDS("经度")
[B5]=.FIELDS("纬度")
[B6]=.FIELDS("PROVINCE")
ELSE: MsgBox "找不到该名称"
End If
end with
conn.Close
Set conn = Nothing
End Sub
更多追问追答
追答
.Open "select * from 基站信息 where 地点='" & [b3] & "'", conn, adOpenKeyset, adLockOptimistic改成
.Open "select * from 基站信息 where 地点='" & [b3] & "'", 3, 3
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询