[英]vba ActiveX can't create odbc.connection object
I'm trying to create ODBC connection in order to be able to perform a simple sql query on one of the tables from my SQL DB. 我正在尝试创建ODBC连接,以便能够对来自我的SQL DB的表之一执行简单的sql查询。
Below is my code and I'm not sure what I'm doing wrong but I keep getting ActiveX can't create an object
error and the following line is highlighted: Set con = CreateObject("ODBC.Connection")
. 下面是我的代码,我不确定自己在做什么错,但是我一直在获取ActiveX can't create an object
错误,并突出显示了以下行: Set con = CreateObject("ODBC.Connection")
。
Private Sub findBtn_Click()
Dim s
Dim con As Object 'OdbcConnection
Dim strCon
Dim rsSearch
Dim strSql
Dim mystring As String
Dim cmd 'As OdbcCommand
s = Me.findTxt
mystring = "Select * from CUSTOMER where CUSTOMER.FORENAME1 like '%" & s & "%';"
Set con = CreateObject("ODBC.Connection")
con.Open "ODBC;Driver={SQL Server};" & _
"Server=localhost;" & _
"Database=Customers23;" & _
"UID=admin;" & _
"PWD=admin;"
Set cmd = CreateObject("ODBC.Command")
cmd = mystring
Me.resTxt = "Connected!"
MsgBox ("Connected")
End Sub
Try to replace ODBC.Connection with ADODB.Connection. 尝试用ADODB.Connection替换ODBC.Connection。
Same with ODBC.Command 与ODBC.Command相同
You can find an example here How do I setup an ADODB connection to SQL Server 2008 in Microsoft Access 2010? 您可以在此处找到示例。 如何在Microsoft Access 2010中设置与SQL Server 2008的ADODB连接?
Also see that link on how to use the Command object. 另请参见有关如何使用Command对象的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.