title: How to populate a ListBox with a ADODB.Recordset (Error 91) To Do Autocompletion in Access
body: <p>I work on an Access DB and I have to use a Datasource connection to a SQL Server.</p>
  
  <p>To do that I use the ADODB object with :    </p>
  
  <p>-ADODB.Connection</p>
  
  <p>-ADODB.Recordset</p>
  
  
  
  <p><em><strong>Code Up-to-date, following an observation of Ian Kenney</em></strong>  </p>
  
  <pre class="lang-vb prettyprint-override"><code>   Dim cnn As ADODB.Connection
     Set cnn = New ADODB.Connection
     Dim rs As ADODB.Recordset
  
     cnn.ConnectionString = "driver={SQL Server};provider=SQLOLEDB;server=10.****;uid=****readonly;pwd=****readonly;database=****"
     cnn.Open
  
    Set rs = cnn.Execute("SELECT [MATRI], [NOMPRE] FROM SCHEME_DB.TABLE WHERE NOMPRE LIKE '*" &amp; Me.Textbox_recherche.Text &amp; "*'")
  
  
  
    Me.Liste_choix.RowSourceType = "Table/List"
    Me.Liste_choix.Recordset = rs
  
    rs.Close
    cnn.Close
  </code></pre>
  
  <p>(This code (a part of the code) is a way to do an Autocompletion in Access with a TextBox and a ListBox)</p>
  
  <p>And I have an error 91 when I run this code : "Error 91: Object variable or With block variable not set" .</p>
  
  <p>I don't understand how to resolve this issue.</p>
  
  <p>Thanks in advance.</p>