title: VBA Insert Query: "Query input must contain at least one table or query""
body: <p>I am importing data from an Excel spreadsheet into <code>tblPOLinesTemp</code> table, and then I have to apppend those to <code>tblPOLines</code> table. I am trying to execute an <code>insert into</code> SQL statement from VBA, but keep getting "Query input must contain at least one table or query" as error, and I cannot seem to figure out what is wrong as the SQL statement works when running it in Access! It is driving me crazy! Can you help?</p>
  
  <p>My code (I have Dim'ed AppendPOlines as String): </p>
  
  <pre><code>AppendPOLines = "INSERT INTO tblPOlines ( PurchaseOrderID, PurchaseOrderLineID, [Material#], FirstDeliveryDate, Quantity, CreatedBy )" _
      &amp; "SELECT tblPOLinesTemp.PurchaseOrderID, tblPOLinesTemp.PurchaseOrderLineID, tblPOLinesTemp.[Material#], tblPOLinesTemp.FirstDeliveryDate, tblPOLinesTemp.Quantity, [TempVars]![VarUserID] AS CreatedBy" _
      &amp; "FROM tblPOLinesTemp LEFT JOIN tblPOlines ON (tblPOLinesTemp.PurchaseOrderLineID = tblPOlines.PurchaseOrderLineID) AND (tblPOLinesTemp.[PurchaseOrderID] = tblPOlines.[PurchaseOrderID])" _
      &amp; "WHERE (((tblPOlines.PurchaseOrderLineID) Is Null) AND ((tblPOlines.PurchaseOrderID) Is Null));"
  
      CurrentDb.Execute AppendPOLines, dbFailOnError
  </code></pre>
  
  <p>Note that the Left Joins is to ensure that the Query does not insert rows with similar Purchase Order and Purchase Order Line ID - to avoid duplicate rows. </p>
  
  <p>Thank you!</p>