+ Reply to Thread
Results 1 to 2 of 2

Create Excel Function that Gets Data via ODBC Connection

  1. #1
    Registered User
    Join Date
    01-29-2014
    Location
    Minnesota
    MS-Off Ver
    Excel 2010
    Posts
    2

    Create Excel Function that Gets Data via ODBC Connection

    Good afternoon,

    Below is a modified version of code I found in the internet. When the code gets to oRecordset.Open mySQL, I get a run-time error 3709. I'm pretty certain that I have all of the library references set up properly. There is something wrong with the creation of my recordset. Do you know what I am doing wrong?

    Sub test2()

    Set OConnection = New ADODB.Connection

    Dim oRecordset As ADODB.Recordset
    Set oRecordset = New ADODB.Recordset

    OConnection.Open "provider=sqloledb;data source=TheServerName;" & _
    "Trusted_Connection=yes;initial catalog=TheTable;"

    'check connection status
    MsgBox OConnection.State

    'get names of tables
    Set rs = OConnection.OpenSchema(adSchemaTables)
    While Not rs.EOF
    Debug.Print rs!TABLE_NAME
    rs.MoveNext
    Wend

    mySQL = "SELECT * FROM REAL_PROPERTY_MULTIPLE;"
    MsgBox OConnection.State
    MsgBox mySQL
    oRecordset.Open mySQL

    OConnection.Close

    End Sub

  2. #2
    Registered User
    Join Date
    01-29-2014
    Location
    Minnesota
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Create Excel Function that Gets Data via ODBC Connection

    I forgot to mention the purpose of the code and some other pertinent information. I want to be able to open a recordset. After I am able to do this, I want to create an Excel function. I tested for connectivity and I tested that I could do something with the connection(print the table names). I can't figure out the how to create the record set.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Use ODBC connection without setting it up in ODBC administration
    By ExcelGal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-18-2012, 09:59 AM
  2. Replies: 0
    Last Post: 07-01-2010, 09:34 AM
  3. Excel VBA makes ODBC connection to Access-How do you close the connection?
    By MrHockey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-04-2010, 06:29 PM
  4. Excel ODBC Connection problem.
    By ebbo in forum Excel General
    Replies: 0
    Last Post: 04-07-2009, 04:55 AM
  5. [SOLVED] How to Switch the ODBC connection in Excel
    By Pete Petersen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2005, 03:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1