会用vb数据库连接,你在vba种直接使用vb的方式即可
可参考下面的代码
------------------
Public Function ConnectDB()
cs = "Provider=MicrosoftjetOLEDB40;Data Source="
'connConnectionString = CS & appPath & "\Score5mdb"
connConnectionString = cs & "F:\Scview\score4mdb"
'cs="Provider=SQLOLEDB;Server=JF705;Database=mytest;Uid=sa;pwd=lmlm"
'cs="Provider=SQLOLEDB;Server=JF705\ETSERVER;Database=mytest;Uid=sa;pwd=lmlm"
'cs="Provider=SQLOLEDB;Server=JF705;Database=mytest;Uid=sa1;pwd=lmlm"
'connConnectionString=cs
connOpen
'responsewrite conn
'responseend
End Function
Private Function query(ByVal nam As String, ByVal path As String)
Dim con As Variant, rst As Variant
Dim sql As String
Set con = CreateObject("adodbconnection")
'conOpen "DRIVER={Microsoft Access Driver (mdb:accdb)};DBQ=" & path
'上面这种方式连接数据库03版以前的EXCEL没问题,07以后得用下面这种驱动,我么有测试,估计得安装07版
'OFFICE里面的工具
conOpen "Provider=MicrosoftAceOLEDB120;Data Source=" & path
sql = "select from data where name='" & nam & "'"
Set rst = conExecute(sql)
If rstEOF Then
query = "0"
Else
query = rst(2) & " _ " & rst(1)
End If
conClose
Set rst = Nothing
Set con = Nothing
End Function
以上就是关于vba中如何实现取sql数据库数据全部的内容,包括:vba中如何实现取sql数据库数据、VBA如何调用MDB数据并输出、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)