Dim oConn As ADODB.Connection Dim rs As ADODB.Recordset 'remove dangerous characters Function esc(txt As String) esc = Trim(Replace(txt, "'", "\'")) End Function Private Sub cmdInsertData_Click() On Error GoTo ErrHandler Set rs = New ADODB.Recordset Set oConn = New ADODB.Connection oConn.Open "DRIVER={MySQL ODBC 5.1 Driver};" & _ "SERVER=myserver;" & _ "DATABASE=mydatabase;" & _ "USER=myuser;" & _ "PASSWORD=mypassword;" & _ "Option=3" 'number of rows with records Dim height As Integer height = Worksheets("myworksheet").UsedRange.Rows.Count 'insert data into SQL table With Worksheets("myworksheet") Dim rowtable As Integer Dim strSQL As String For rowtable = 2 To height strSQL = "INSERT INTO mysqltable (column1, column2, column3) " & _ "VALUES ('" & esc(Trim(.Cells(rowtable, 1).Value)) & "', '" & _ esc(Trim(.Cells(rowtable, 2).Value)) & "', '" & _ esc(Trim(.Cells(rowtable, 3).Value)) & "')" rs.Open strSQL, oConn, adOpenDynamic, adLockOptimistic Next rowtable End With MsgBox "Insert with success " & Trim(Str(rowtable - 2)) & " records", vbInformation, "Verification Data Entry"
This code i need fix it