简体   繁体   English

vba ActiveX无法创建odbc.connection对象

[英]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.

相关问题 访问VBA ODBC连接失败 - Access VBA ODBC connection failed [Microsoft] [ODBC驱动程序管理器]无法建立与SQL Server的连接 - [Microsoft][ODBC Driver Manager] Can't establish connection to SQL server 访问 VBA 生成 ODBC 连接字符串恢复 - Access VBA generated ODBC connection string reverts 需要远程创建到SQl服务器的ODBC连接 - Need to remotely create an ODBC connection to a SQl server 无法通过CodeIgniter查询构建器和ODBC连接获取数据 - Can't get data through CodeIgniter query builder from and ODBC Connection Python ODBC (pyodbc) 与 MSSQL 服务器的连接失败,并出现错误“无法打开库...找不到文件”-但驱动程序文件在那里 - Python ODBC (pyodbc) connection to MSSQL server fails with error "Can't open lib ... file not found"- but driver file is there 使用Windows NT身份验证和特定用户创建ODBC连接 - Create an ODBC connection using Windows NT Authentication with a specific user ODBC无法使用参数过滤数据 - ODBC can't filter data with parameter 如何创建到一个远程SQL Server的新的ODBC连接 - How to create a new ODBC connection to one remote SQL Server 我可以在ODBC和ADO之间共享一个数据库连接吗? - Can I share a single database connection between ODBC and ADO?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM