title: Import Data into Excel from Access Table, Syntax error in FROM Clause
body: <p>I am running this code to import data from Access to Excel and getting a run-time error:</p>
  
  <pre><code> "syntax error in FROM clause." 
  </code></pre>
  
  <p>The table in Access has four columns: <code>Date</code>, <code>Time</code>, <code>Tank</code>, <code>Comments</code>, and I want to import <code>Time</code> and <code>Tank</code>, based on a date in the spreadsheet. 
  I want to order these columns in the order <code>Tank</code>, <code>Time</code>.  </p>
  
  <p>The error is in the line: </p>
  
  
  
  <pre class="lang-vb prettyprint-override"><code>.Open "Select [Time], [Tank]  FROM [UnitOneRouting] WHERE [Date] = " &amp; RpDate &amp; " ORDER BY Tank, Time", cn, adOpenStatic, adLockOptimistic, adCmdTable
  </code></pre>
  
  <p>Code Snippet:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub ADOImportFromAccessTable()
      Dim DBFullName As String
      Dim TableName As String
      Dim TargetRange As Range
      Dim RpDate As Range
  
      DBFullName = "U:\Night Sup\Production Report 2003 New Ver 5-28-10_KA.mdb"
      TableName = "UnitOneRouting"
      Worksheets("TankHours").Activate
      Set TargetRange = Range("C5")
      Set RpDate = Range("B2").Cells
  
  
      Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
          Set TargetRange = TargetRange.Cells(1, 1)
          ' open the database
          Set cn = New ADODB.Connection
          cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &amp; _
              "U:\Night Sup\Production Report 2003 New Ver 5-28-10_KA.mdb" &amp; ";"
          Set rs = New ADODB.Recordset
             With rs
          ' open the recordset
          ' filter rows based on date
              .Open "Select [Time], [Tank]  FROM [UnitOneRouting] WHERE [Date] = " &amp; RpDate &amp; " ORDER BY Tank, Time", cn, adOpenStatic, adLockOptimistic, adCmdTable
           rs.Open , TargetRange
           TargetRange.CopyFromRecordset rs
  
          End With
          rs.Close
          Set rs = Nothing
          cn.Close
          Set cn = Nothing
      End Sub
  </code></pre>