title: Deleting mysql table entries using a macro
body: <p>I am writing a macro by which I want to delete few names in column A of sheet 2 from the server table called login.  </p>
  
  <p>Database name is "my_db" and table name is login. I calling connection to connect to the server databse. Following is the complete code :-</p>
  
  <pre><code>Dim cnt As ADODB.Connection
  Dim rst As ADODB.Recordset
  Dim Sql As String
  Sub Button1_Click()
  Dim Ws As Worksheet
  Dim Var As String
  Dim i As Integer
  i = 1
  Set Ws = Worksheets("Sheet2")
  Var = "login"
  Sql = "name"
  Call Connection
  
  
  Do
  
  Sql = " Delete From " &amp; " " &amp; Var &amp; "" &amp; " Where name" = "Ws.Cells(i, 1)"
  
  
  
  
  
      Call Connection
    i = i + 1
    Loop Until Ws.Cells(i, 1) = ""
  
    MsgBox "All entries deleted from login table"
  
  
  End Sub
  
  Dim strUserName As String
  Dim strPassword As String
  Dim ConnectString As String
  Set cnt = New ADODB.Connection
  
  
  strServerName = "localhost"
  strDatabaseName = "my_db"
  strUserName = "root"
  strPassword = "root1"
  
  
  ConnectString = "DRIVER={MySQL ODBC 5.1 Driver};" &amp; _
                  "SERVER=" &amp; strServerName &amp; _
                  ";DATABASE=" &amp; strDatabaseName &amp; ";" &amp; _
                  "USER=" &amp; strUserName &amp; _
                  ";PASSWORD=" &amp; strPassword &amp; _
                  ";OPTION=3;"
  
  
  
   With cnt
          .CursorLocation = adUseClient
          .Open ConnectString
          .CommandTimeout = 0
          Set rst = .Execute(Sql)
      End With
      'rst.Close
       'cnt.Close
  
      Set rst = Nothing
      Set cnt = Nothing
  
  End Sub
  </code></pre>
  
  <p>But the entries are not getting deleted. There is an error in SQL syntax, can anyone help me with the sql syntax ?</p>