title: Excel SQL VBA: adding more than one cmd parameter
body: <p>I am writing SQL-query, and I get error with string value:</p>
  <pre class="lang-vb prettyprint-override"><code>Dim cn As Object, rs As Object, output As String, sql As String
  Dim dt As Date
  Dim lne As String
  Const adCmdText As Integer = 1, adDate As Integer = 7, adChar As Integer = 8
   
  Set cn = CreateObject(&quot;ADODB.Connection&quot;)
  With cn
      .Provider = &quot;Microsoft.ACE.OLEDB.12.0&quot;
      .ConnectionString = &quot;Data Source=&quot; _
                      &amp; ThisWorkbook.FullName &amp; &quot;;&quot; _
                      &amp; &quot;Extended Properties=&quot;&quot;Excel 12.0 Xml;HDR=YES&quot;&quot;;&quot;
      .Open
  End With
  
  With Worksheets(&quot;Page 2&quot;)
       dt = CDate(Replace(.Cells(i, 2).Value, &quot;.&quot;, &quot;-&quot;))
       lne = .Cells(2, 1).Value ' lne = mystr
  End With
  
  sql = &quot;SELECT Name, SUM(Worktime) as summa FROM [Page 1$] WHERE DateTime = ? AND Line = &quot; &amp; lne &amp; &quot; GROUP BY Name&quot;
  Set cmd = CreateObject(&quot;ADODB.Command&quot;)
  
  With cmd
      .ActiveConnection = cn
      .CommandText = sql
      .CommandType = adCmdText
      
      .Parameters.Append .CreateParameter(&quot;dt&quot;, adDate, 1, , dt)
      
      Set rs = .Execute ' ERROR: One or more required parameters are missing a value.
  End With
  </code></pre>
  <p>I tried to add more than one cmd parameter to solve this problem:</p>
  <pre class="lang-vb prettyprint-override"><code>sql = &quot;SELECT Name, SUM(Worktime) as summa FROM [Page 1$] WHERE DateTime = ? AND Line = ? GROUP BY Name&quot;
  
  Set cmd = CreateObject(&quot;ADODB.Command&quot;)
  
  With cmd
      .ActiveConnection = cn
      .CommandText = sql
      .CommandType = adCmdText
      
      .Parameters.Append .CreateParameter(&quot;dt&quot;, adDate, 1, , dt)
      
      .Parameters.Append .CreateParameter(&quot;lne&quot;, adChar, 2, , lne)
      
      Set rs = .Execute
  End With
  </code></pre>
  <p>But I also get an error. How do I set more than one cmd parameter and use it in my query?</p>
  <p>Table I am working with: <a href="https://drive.google.com/file/d/1NgcB2pm6xDVDn8W-lInOMUMxDag1q5ZD/view?usp=sharing" rel="nofollow noreferrer">here</a>.</p>