what is the difference in the way these work:
Sql = "INSERT INTO mytable (datapath, analysistime,reporttime, lastcalib,analystname,reportname,batchstate,instrument) " & _
"VALUES (dpath, atime, rtime,lcalib,aname,rname,bstate,instrument) SELECT SCOPE_IDENTITY()"
Set rs = cn.Execute
Set rs = rs.NextRecordset
and this:
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("datapath") = dpath
.Fields("analysistime") = atime
.Fields("reporttime") = rtime
.Fields("lastcalib") = lcalib
.Fields("analystname") = aname
.Fields("reportname") = rname
.Fields("batchstate") = bstate
.Fields("instrument") = instrument
.Update ' stores the new record
id=fields.Fields("rowid") ' ** Answer to Question ***
End With
my question is specifically this:
i am in a multiuser environment. immediately after the user adds a record, i need to catch the ROWID of the record added. how do i do this?
this is how i open the recordset:
rs.Open "batchinfo", cn, adOpenKeyset, adLockOptimistic, adCmdTable
The different is the way you add the record and get the result back.
In the first case, you are issuing an
INSERTstatement followed by a call toSCOPE_IDENTITY.In the second case, you open an updatable cursor, add a record into it and read the newly added record back.
Opening a cursor may be quite a resource-intensive operation (this depends on how do you do it). It also can degrade concurrency.