title: When I call a query from Access using VBA, I can't know how many records are on that query. Why?
body: <p>I did a query on MS Access 2010, with the Query Builder, now I'm calling it from VBA. But when I try to use the recordcount to know how many records are on this query, the result is -1. </p>
  
  <p>The code:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Function teste(Optional ByVal consulta As String, Optional ByVal cbAR_valor As String, Optional ByVal cbAR_valor2 As String)
  
  Dim DB As ADODB.Connection
  Dim RST As ADODB.Recordset
  Dim Query As ADODB.Command
  Dim parametro1 As ADODB.Parameter
  Dim parametro2 As ADODB.Parameter
  
  On Error GoTo trataErro
  
  DB_Dir = ThisWorkbook.Path &amp; "\" &amp; "DB2.accdb"
  
  Set DB = New ADODB.Connection
  DB.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; DB_Dir &amp; ";Persist Security Info=False"
  
  Set Query = New ADODB.Command
  Set Query.ActiveConnection = DB
  Query.CommandText = consulta
  Query.CommandType = adCmdStoredProc
  
  ' Pego o valor do param. e adiciono no command
  Set parametro1 = Query.CreateParameter("AR1", adChar, adParamInput, 255)
  Query.Parameters.Append parametro1
  parametro1.Value = cbAR_valor
  
  ' Pego o valor do param. e adiciono no command
  Set parametro2 = Query.CreateParameter("AR2", adChar, adParamInput, 255)
  Query.Parameters.Append parametro2
  parametro2.Value = cbAR_valor2
  
  
  Set RST = Query.Execute
  
  a = RST.RecordCount
  
  linha = 1
  coluna = 1
  ActiveWorkbook.Sheets("Plan2").Cells(CInt(linha), CInt(coluna)).CopyFromRecordset RST
  
  DB.Close
  Set DB = Nothing
  
  Exit Function
  
  trataErro:
      MsgBox ("Erro: " &amp; Err.Description)
  
  
  End Function
  </code></pre>