Results 1 to 7 of 7

exporting data to mysql is giving errors

Threaded View

  1. #1
    Registered User
    Join Date
    06-07-2013
    Location
    Romania
    MS-Off Ver
    Excel 2007
    Posts
    6

    exporting data to mysql is giving errors

    hi,
    i'm trying to make some code i found in a tutorial work.
    i have a mysql database, which i use with another application. i've made a new excel document with the same structure as the table in the database, and i'm trying to send the data there.
    here is the code:

    
    Dim oConn As ADODB.Connection
    Private Sub ConnectDB()
        Set oConn = New ADODB.Connection
        oConn.Open "DRIVER={MySQL ODBC 3.51 Driver};" & _
            "SERVER=localhost;" & _
            "DATABASE=temperature_monitor3;" & _
            "USER=root;" & _
            "PASSWORD=;" & _
            "Option=3"
    End Sub
    
    Function esc(txt As String)
        esc = Trim(Replace(txt, "'", "\'"))
    End Function
    
    Dim rs As ADODB.Recordset
    Private Sub InsertData()
        Set rs = New ADODB.Recordset
        ConnectDB
        With Sheet1
            For rowCursor = 2 To 4
                strSQL = "INSERT INTO tutorial (pid, channel_name, value, description) " & "VALUES ('" & esc(.Cells(rowCursor, 1)) & "', " & "'" & esc(.Cells(rowCursor, 2)) & "', " & esc(.Cells(rowCursor, 3)) & "', " & esc(.Cells(rowCursor, 4)) & ")"
                rs.Open strSQL, oConn, adOpenDynamic, adLockOptimistic
            Next
        End With
    End Sub
    the first part seems to work. doesn't return any errors at least.
    The insertData sub however, returns "Run-time error 424: object required". In this case i renamed the sheet i was working with, after writing the code, and this probably caused the error.
    I tried doing the whole thing all over again, in a new document, without renaming the sheet, and now the error i get is: "Run-time error '-2147217887 (80040e21)': Automation Error"

    can anyone spot a problem? on the site where i got the tutorial, the comments seem to say the code works for most people, however, a few complained about the same error, and got no answer that helped.

    thank you for your time

    maybe i should add a link to the tutorial: http://www.heritage-tech.net/908/ins...cel-using-vba/
    Last edited by john12345678; 06-07-2013 at 05:11 AM.

Thread Information

Users Browsing this Thread

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

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