ADODBRecordset.UpdateBatch
I have the following bit of code.
VB Code:
Dim myConn as New ADODB.Connection
Dim myRS as New ADODB.Recordset
myConn.Open "myDSN"
myRS.Open "SELECT * FROM myTable WHERE 0=1", myConn, adOpenDynamic, adLockBatchOptimistic
myRS.AddNew
myRS.Fields("Field1").Value = strFoo
myRS.Fields("Field2").Value = strBar
myRS.UpdateBatch
myRS.Close
myRS.Open "SELECT IndexField FROM myTable WHERE " & _
"Field1 = '" & strFoo & "' AND " & _
"Field2 = '" & strBar & "'", _
myConn, adOpenDynamic, adLockBatchOptimistic
intIndex = myRS.Fields("IndexField").Value
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?