title: SQL Excel VBA Run-time Error 3709 Invalid Connection
body: <p>This is my first question so constructive criticism is welcome! I am attempting to query an access database from excel vba and place the return information into an Excel range. I get this error:</p>
  
  <blockquote>
    <p>Error Message: "Run-time error '3709' The connection cannot be used to
    perform this operation. It is either closed or invalid in this
    context."</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>Sub Importfromaccess()
          Path = "C:\Users\myUser\Desktop\Database1.accdb"
  
          Set cn = CreateObject("ADODB.connection")
  
          cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" &amp; Path &amp; ";"
  
          Set rs1 = CreateObject("ADODB.recordset")
  
          rs1.activeconnection = cn
  
          Dim strSQL As New ADODB.Command
  
          strSQL.CommandText = "SELECT * FROM Tooling WHERE TID=BD0001"
          strSQL.CommandType = adCmdText
  
          Set rs1 = strSQL.Execute ' This is the line the error occurs on
  
          Sheets("Calc").Range("K1").CopyFromRecordset rs1
  End Sub
  </code></pre>
  
  <p>I have enabled the following references:</p>
  
  <ol>
  <li>Visual Basic For Applications,</li>
  <li>Microsoft Excel 16.0 Object Library,</li>
  <li>OLE Automation,</li>
  <li>Microsoft Office 16.0 Object Library,</li>
  <li>Microsoft Access 16.0 Object Library,</li>
  <li>Microsoft ActiveX Data Objects 2.0 Library,</li>
  </ol>
  
  <p>I tried placing the line:</p>
  
  <pre><code>cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" &amp; Path &amp; ";"
  </code></pre>
  
  <p>right before the error line and received this error:</p>
  
  <blockquote>
    <p>Run-time error '3705': Operation is not allowed when the object is
    open.</p>
  </blockquote>
  
  <p>Anybody know what my problem might be?</p>