title: VBA excel macro to read acess database : How can I get the result of my SQL query(select count(col_name) from table name) in a variable
body: <pre><code>Sub verify_db()
  
  path="c:\temp\temp1.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
  
  'SQL query to get the count 
  
  strsql = "SELECT count(col_name)  FROM tablename WHERE somecol=some_value"
  
   rs1.Open strsql
  
  'Result of count which I'm getting through the above SQL query will save in cell 
  A1 in sheet named - Sheet1
  
         Sheets("Sheet1").Range("A1").CopyFromRecordset rs1
  
         count1 = Sheets("input1").Range("A1")
  
   End sub       
  </code></pre>
  
  <p>In the above code I'm getting value for the variable count  indirectly .</p>
  
  <p>How can I get the result directly in the variable count1?</p>
  
  <p>Thanks in advance</p>