title: Importing data from excel to mysql database using vba
body: <p>I´m trying to import data into a MySQL Database, i have searched for many examples and solutions but it didn´t working and i have no idea why. Below is my vba code. I am getting runtime error 2147217900(80040e14) saying that you have an error in your sql syntax; chek the manual that corrsponds to your mysqlfor the right syntax to use near '='41282'</p>
  
  <pre><code>Sub Getdata()
  Dim conn As New ADODB.Connection
  Dim server_name As String
  Dim database_name As String
  Dim user_id As String
  Dim password As String
  
  Dim a As Long ' counter
  Dim i As Long, j As Variant, k As Long
  Dim sqlstr As String ' SQL to perform various actions
  Dim table1 As String, table2 As String
  Dim field1 As String, field2 As String
  Dim field3 As String
  Dim rs As ADODB.Recordset
  
  sqlstr = "INSERT INTO" &amp; table1 &amp; "SET" _
  &amp; field1 &amp; " = '" &amp; i &amp; "', " _
  &amp; field2 &amp; " = '" &amp; j &amp; "', " _
  &amp; field3 &amp; " = '" &amp; k &amp; "'"
  conn.Execute sqlstr
  Next a
  End With
  skipwrite:
  End Sub
  </code></pre>