title: Need Help related to ADODB VBA Macro SQL SERVER
body: <p>I am trying to load data to my SQL server 2008 R2 Database using VB macro from an excel sheet.
  I have already written a macro that was working fine for one table ,but when i modify it to insert data into another table i am getting the error </p>
  
  <p><code>
  Runtime Error'2147217900(80040e14)'
  [microsoft][ODBC SQL Server Driver][SQL SERVER]Incorrect syntax near '9'</code></p>
  
  <p>and when i press debug this line is getting highlighted</p>
  
  <p><code>oCm.Execute iRecAffected</code></p>
  
  <p>The table that i am trying to update has 6 fields  a,b,c,d,e,f of type int,int,int,datetime,datetime and int</p>
  
  <p>I believe the error is because there is something i am not doing for datetime fields in this line </p>
  
  <p><code>oCm.CommandText = "Insert Into Table (a, b, c, d, e, f) Values (" &amp; a &amp; " ," &amp; b &amp; " ," &amp; c &amp; "," &amp; d &amp; "," &amp; e &amp; "," &amp; f &amp; ")"</code></p>
  
  <p>can some one please tell me what could be the issue.</p>
  
  <p>`</p>
  
  <pre><code>Dim DestinationWorkBook       As Workbook
  Dim SourceWorkBook    As Workbook
  Dim DestinationWorkBook1       As Workbook
  Dim SourceWorkBook1    As Workbook
  Dim oCm As ADODB.Command
  Dim a As Integer
  Dim b As Integer
  Dim c As Integer
  Dim d As Date
  Dim e As Date
  Dim f As Integer
  Dim iRecAffected As Integer
  Dim CurrentRow           As Integer
  Set DestinationWorkBook = ThisWorkbook
  Set SourceWorkBook = ThisWorkbook
  Set DestinationWorkBook1 = ThisWorkbook
  Set SourceWorkBook1 = ThisWorkbook
  Dim b                    As String
  Dim rngRange             As Range
  Dim a                    As String
  
       LoopContinue = True
  
  
       CurrentRow3 = 2
      loop1 = True
  
       CurrentRow = 2
       DestinationWorkBook.Activate
       Worksheets("errors").Select
       Rows("1:1500").Select
       Selection.Delete Shift:=xlUp
       SourceWorkBook.Activate
       Worksheets("Final_output").Select
  Dim oCon As ADODB.Connection
   Dim oRs As ADODB.Recordset
   Set oCon = New ADODB.Connection
   oCon.ConnectionString = "deleted"
   oCon.Open
   Set oCm = New ADODB.Command
   oCm.ActiveConnection = oCon
   While loop1 = True
   a = (Range("A" &amp; CStr(CurrentRow)).Value)
   b = (Range("B" &amp; CStr(CurrentRow)).Value)
   c = (Range("C" &amp; CStr(CurrentRow)).Value)
   d = (Range("D" &amp; CStr(CurrentRow)).Value)
   e = (Range("E" &amp; CStr(CurrentRow)).Value)
   f = (Range("F" &amp; CStr(CurrentRow)).Value)
   If Len(Range("A" &amp; CStr(CurrentRow)).Value) = 0 Then
   loop1 = False
   End If
    If (loop1 &lt;&gt; False) Then
  
   oCm.CommandText = "Insert Into Table (a, b, c, d, e, f) Values (" &amp; a &amp; " ," &amp; b &amp; " ," &amp; c &amp; "," &amp; d &amp; "," &amp; e &amp; "," &amp; f &amp; ")"
  oCm.Execute iRecAffected
  CurrentRow = CurrentRow + 1
  End If
  Wend
  oCon.Close
  End Sub
  </code></pre>
  
  <p>`</p>