Sorry to cross-post, but after getting no traffic in the other forum, I thought I might get better response here.

I have the following bit of code.

VB Code:
  1. Dim myConn as New ADODB.Connection
  2.   Dim myRS as New ADODB.Recordset
  3.  
  4.   myConn.Open "myDSN"
  5.  
  6.   myRS.Open "SELECT * FROM myTable WHERE 0=1", myConn, adOpenDynamic, adLockBatchOptimistic
  7.  
  8.   myRS.AddNew
  9.   myRS.Fields("Field1").Value = strFoo
  10.   myRS.Fields("Field2").Value = strBar
  11.   myRS.UpdateBatch
  12.  
  13.   myRS.Close
  14.  
  15.   myRS.Open "SELECT IndexField FROM myTable WHERE " & _
  16.             "Field1 = '" & strFoo & "' AND " & _
  17.             "Field2 = '" & strBar & "'", _
  18.             myConn, adOpenDynamic, adLockBatchOptimistic
  19.   intIndex = myRS.Fields("IndexField").Value
  20.   myRS.Close

Is there a safe way (that will work with MS Access, MS SQL Server, and Oracle) that I can get the autonumber field (IndexField) without closing and reopening the recordset? Are there any other places that I can make this code safer, use more accepted conventions?