title: How to find the next ID auto number from access table and display the number in an Excel userform?
body: <p>I would like take the next ID auto number from an access table and display it in a textbox on an excel userform. I have found this code and I've played around with it but I'm not getting anywhere and completely lost. I'd be grateful if someone could point me in the right direction to solve it.</p>
  
  <pre><code>    Dim con As Object: Set con = CreateObject("ADODB.Connection")
      Dim rs As Object: Set rs = CreateObject("ADODB.Recordset")
      Dim sql As String
  
      connectionstring = "PROVIDER=Microsoft.ACE.OLEDB.12.0;"
      connectionstring = connectionstring &amp; "DATA Source=C:\Users\MyPc\Desktop\Database1.accdb;"
      con.Open connectionstring
  
      sql = "select max(ID) as maxvalue from TableOne"
  
      con.Execute sql
  
      NextValue = (maxvalue) + 1
  
       MsgBox NextValue
       userform1.textbox2.value = NextValue
       rs.Close
       Set rs = Nothing
  </code></pre>