[英]Connect Excel to Access - VBA
I get a "User-defined type not defined" error when I execute the below code, and the 当我执行下面的代码时,我得到一个“用户定义的类型未定义”错误
"objCon As ADODB.Connection" “objCon As ADODB.Connection”
is highlighted on the first line. 在第一行突出显示。 I am trying to set a connection from Excel to Access via VBA code. 我试图通过VBA代码设置从Excel到Access的连接。 Thank you for any advice! 谢谢你的建议!
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
You can do one of the following 您可以执行以下操作之一
set objCon = CreateObject("ADODB.Connection")
set rstRec = CreateObject("ADODB.Recordset")
Or in VBA Editor Tools-->Reference--> Add Microsoft ActiveX Data Object XY Library
或者在VBA编辑器工具 - >参考 - >添加Microsoft ActiveX Data Object XY Library
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.