title: Pass Through Query With Parameters
body: <p>I am attempting to run a <code>Access 2013</code> pass through query that takes two parameters from my VBA syntax.  When I run this, I get a compile error of</p>
  
  <blockquote>
    <p>expected end of statement<br>
    " and "</p>
  </blockquote>
  
  <p>How should this sub be modified in order for this to be valid sql string?</p>
  
  <pre><code>Public Sub GeneratePassThroughForJob()
  
      Dim qdfPassThrough As DAO.QueryDef, MyDB As Database
      Dim strConnect As String, d1 As String, d2 As String, Dim SQL As String
  
      d1 = Format(Forms!DataPull!txtd1, "YYYY-MM-DD")
      d2 = Format(Forms!DataPull!txtd2, "YYYY-MM-DD")
  
      If Not IsNull(CurrentDb.QueryDefs("qrySQLPass").SQL) Then
          CurrentDb.QueryDefs.Delete "qrySQLPass"
      End If
  
      Set MyDB = CurrentDb()
      Set qdfPassThrough = MyDB.CreateQueryDef("qrySQLPass")
      strConnect = "ValidSQLServerConnectionString"
  
      qdfPassThrough.Connect = "ODBC;" &amp; strConnect
  
      SQL = "Select fname, lname, address from einfo where startdate between "&amp;d1&amp;" and "&amp;d2&amp;""
  
      qdfPassThrough.SQL = "Select fname, lname, address from einfo where startdate between "&amp;d1&amp;" and "&amp;d2&amp;""
  
      qdfPassThrough.ReturnsRecords = False
      qdfPassThrough.Close
  
      Application.RefreshDatabaseWindow
  
      DoCmd.OpenQuery "qrySQLPass", acViewNormal, acReadOnly
      DoCmd.Maximize
  End Sub
  </code></pre>