title: Access: Get newly created auto number in DAO
body: <p>I have a code in DAO that connects to a linked table in SQL Server 2008. I need to get the newly created auto number on <code>.AddNew</code>.</p>
  
  <pre><code>Set db = CurrentDb
  Set rs = db.OpenRecordset("AuditTrail")
  
  rs.AddNew
  rs("ActionID") = actionAdd
  rs("dtDateTime") = Now()
  rs("FormName") = frmName
  rs("TableName") = tblName
  rs("RecordID") = actionAdd
  rs("Comment") = Nz(comment, "")
  rs("UserID") = UserIDName
  rs("UsernamePC") = VBA.Environ("USERDOMAIN")
  rs("DomainPC") = VBA.Environ("USERDOMAIN")
  rs("ComputerNamePC") = VBA.Environ("COMPUTERNAME")
  rs.Update
  
  rs.Close
  </code></pre>
  
  <p>If I use <code>rs("AuditTrailID")</code> before <code>rs.Close</code>, it returns 1 (the first entry).</p>