title: VBA: Querying Access with Excel. Why so slow?
body: <p>I found this code online to query Access and input the data into excel (2003), but it is much slower than it should be:</p>
  
  <pre><code>Sub DataPull(SQLQuery, CellPaste)
  Dim Con As New ADODB.Connection
  Dim RST As New ADODB.Recordset
  Dim DBlocation As String, DBName As String
  Dim ContractingQuery As String
  
  If SQLQuery = "" Then
  
  Else
      DBName = Range("DBName")
      If Right(DBName, 4) &lt;&gt; ".mdb" Then DBName = DBName + ".mdb"
  
      DBlocation = ActiveWorkbook.Path
      If Right(DBlocation, 1) &lt;&gt; "\" Then DBlocation = DBlocation + "\"
  
      Con.ConnectionString = DBlocation + DBName
      Con.Provider = "Microsoft.Jet.OLEDB.4.0"
      Con.Open
  
      Set RST = Con.Execute(SQLQuery)
      Range(CellPaste).CopyFromRecordset RST
  
      Con.Close
  End If
  
  End Sub
  </code></pre>
  
  <p>The problem is that this code takes very long.  If I open up Access and just run the query in there it takes about 1/10th the time.  Is there anyway to speed this up? Or any reason this might be taking so long?  All my queries are simple select queries with simple where statements and no joins.  Even a <code>select * from [test]</code> query takes much longer than it should.</p>
  
  <p>EDIT:  I should specify that the line</p>
  
  <p><code>Range(CellPaste).CopyFromRecordset RST</code></p>
  
  <p>was the one taking a long time.</p>