执行以下代码时出现“未定义用户定义的类型”错误,并且
“objCon 作为 ADODB.Connection”
在第一行突出显示。我正在尝试通过 VBA 代码设置从 Excel 到 Access 的连接。感谢您的任何建议!
Private objCon As ADODB.Connection
Private rstRec As ADODB.Recordset
Private strQry
Sub Connect()
Dim strConn As String
Set objCon = New ADODB.Connection
objCon.Mode = adModeReadWrite
If objCon.State = adStateClosed Then
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "C:\DB\Db.accdb;Persist Security Info=False;"
objCon.ConnectionString = strConn
objCon.Open
End If
End Sub