title: Excel VBA - search range and connected SQL ADODB recordsets for match write Resultset in column
body: <p>I have an Excel (2010) table with two data sources:</p>
  
  <ol>
  <li>Access 2010 DB</li>
  <li>SQL Server 2008 R2</li>
  </ol>
  
  <p>I have data in columns A:I from the Access DB. In column A I have the record's ID, this ID  corresponds to the ID column in the table from my SQL DB. </p>
  
  <p>I am trying to search through IDs in column A and if it matches an ID in the SQL DB, I want to display data from the "coOverview" column from the SQL table in column J. </p>
  
  <p><strong>In short, "If ID = coID, then write coOverView to column J"</strong></p>
  
  <p><a href="https://i.stack.imgur.com/BnhkW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BnhkW.png" alt="Combined Dataset"></a>
  I have successfully been able to connect and retrieve the desired record-set and copy/fill down column J, so I know I am able to successfully connect and read the data in my SQL table. Now I need to copy the data in coOverview from my SQL table ONLY if the ID matches the ID in column A.</p>
  
  <pre><code>Sub RetrieveOverview()
  
  Dim cn As New ADODB.Connection
  Dim rs As New ADODB.Recordset
  Dim ConnectionString As String
  Dim query As String
  
  Set cn = New ADODB.Connection
  
      ConnectionString = "Provider=SQLOLEDB;Password=***;Persist Security Info=True;User ID=*****;Data Source=***;Initial Catalog=**"
  
      cn.Open ConnectionString
      cn.CommandTimeout = 900
  
  
      query = "SELECT coOverview FROM SQLTable"
  
      rs.Open StrQuery, cn
  
      Sheets(1).Range("J2").CopyFromRecordset rs
      End Sub
  </code></pre>
  
  <p>I don't know if I should be the conditions in the SQL statement or in a loop. </p>