【发布时间】:2018-01-16 06:24:42
【问题描述】:
我的数据库访问总是在不同的路径中,但在与我的工作簿相同的文件夹中。
Private Sub CommandButton14_Click()
Dim cn As Object
Dim rs As Object
Dim strSql As String
Dim strConnection As String
Set cn = CreateObject("ADODB.Connection")
'here I want to use current directory as path for my mdb
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=D:\FicheMacro\PGDB.mdb"
strSql = "SELECT Count(*) FROM AQ_DGE_MOD;"
cn.Open strConnection
Set rs = cn.Execute(strSql)
MsgBox rs.Fields(0) & " rows in MyTable"
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
【问题讨论】:
-
我不熟悉 Connections,但this 可能会有所帮助。