title: MS Access OpenRecordset and too few parameters issue
body: <p>This is a follow-up question of <a href="https://stackoverflow.com/questions/46982291/ms-access-openredcordset-reading-wrong-string/46983213?noredirect=1#comment80918070_46983213">MS Access OpenRedcordset reading wrong string</a>. I'm certain that I have enough parameters, fields declaration to pass values to <code>OpenRecordSet</code> method but I am still stuck. </p>
  
  <p><strong>General explanation:</strong></p>
  
  <ol>
  <li>Users input start date and end date on a form that filters my query 2_Total (single value) <a href="https://i.stack.imgur.com/L0KDU.jpg" rel="nofollow noreferrer">My query</a></li>
  <li>Run the VBA function that exports the query to an excel file</li>
  </ol>
  
  <p><strong>Problem</strong>:
  <em>Too few parameters. Expected 4 error</em> on  <code>Set rst = qry.OpenRecordset(dbOpenDynaset)</code></p>
  
  <p><strong>SQL</strong>   <a href="https://i.stack.imgur.com/azjaV.jpg" rel="nofollow noreferrer">Design View</a></p>
  
  <pre class="lang-sql prettyprint-override"><code>PARAMETERS [BeginDate] DateTime, [EndDate] DateTime;
  SELECT Sum(dbo_SO_SalesHistory.DollarsSold) AS SumOfDollarsSold
  FROM dbo_SO_SalesHistory
  WHERE (((dbo_SO_SalesHistory.InvoiceDate) Between [Forms]![RUN]![textBeginOrderDate] And [Forms]![RUN]![textendorderdate]));
  </code></pre>
  
  <p><strong>VBA</strong></p>
  
  <pre class="lang-vb prettyprint-override"><code>Option Compare Database
  
  Option Explicit
  Public Function Trans2()
  
      Dim xlApp As Excel.Application
      Dim xlWB As Excel.Workbook
      Dim xlWS As Excel.Worksheet
      Dim acRng As Variant
      Dim xlRow As Integer
  
      Dim db As DAO.Database
      Dim qry As QueryDef
      Dim rst As Recordset
      Dim prm As DAO.Parameter
      Dim strSQL As String
  
      Set db = CurrentDb
      Set xlApp = New Excel.Application
      Set xlWB = xlApp.Workbooks.Open("C:\Users\J\Desktop\August 2017.xlsx")
      Set xlWS = xlWB.Worksheets("Totals")
  
      xlRow = (xlWS.Columns("K").End(xlDown).Row)
  
      Set qry = db.QueryDefs("2_Total")
  
      qry![BeginDate] = [Forms]![Run]![textBeginOrderDate]
      qry![EndDate] = [Forms]![Run]![textendorderdate]
  
      Set rst = qry.OpenRecordset(dbOpenDynaset)
  
      Dim c As Integer
      c = 11   'C is the one that stores column number, in which c=1 means column A, 11 is for column K, 12 for Column L
      xlRow = xlRow + 11
  
       Do Until rst.EOF
          For Each acRng In rst.Fields
              xlWS.Cells(xlRow, c).Formula = acRng
              c = c + 1
          Next acRng
          xlRow = xlRow + 1
          c = 1
          rst.MoveNext
          If xlRow &gt; 25 Then GoTo rq_Exit
      Loop
  
  
  rq_Exit:
      rst.Close
      Set rst = Nothing
      Set xlWS = Nothing
      xlWB.Close acSaveYes
      Set xlWB = Nothing
      xlApp.Quit
      Set xlApp = Nothing
      Exit Function
  
  End Function
  </code></pre>
  
  <p>The following didn't solve the issue. I still have Too few parameters. Expected 4 error. </p>
  
  <pre><code>qry.Parameters("BeginDate").Value = [Forms]![Run]![textBeginOrderDate]
  qry.Parameters("EndDate").Value = [Forms]![Run]![textendorderdate] 
  </code></pre>