Also yes it needs to be viewed before the UPDATE as after the update there
Actually, here is a good approach:
rstRecords.AddNew
' code can go here to add data, or set values to the reocord...
........
........
rstRecords.Update
rstRecords.Bookmark = rstRecords.LastModified
lngNext = rstRecords!ID
rstRecords.Close
Set rstRecords = Nothing
MsgBox lngNext
Note how I actually finish the update..and then move the record back to the
updated. This is also nice for code that needs to reference the values in
the reocrdset...(and thus not have to declare extra vars to hold soem
values).
So, often after I do a update, I want the recordsset to REMAIN on the same
record. This gives me use of the auotnumber..and also just keeps the code
on the reocrdset....
In addtion, while when using JET, you can go
rstRecords.AddNew
AT this point, the auto number id is available..even if you have NOT YET
modified any values. However, if you use a server based system like Sql
server, then the autonumber field is NOT available until AFTER the update.
Thus, the above code that uses the lastmodifeed setting is better, since it
will work wit both JET, or sql server (or mysql..or whatever). So, you
likely should adopt a coding standard that executes the update...and THEN
grabs the autonumber field, since this will work with most database systems
from JET...all the way to oracle....
Note well that you can also use a sql statement go get that last number (jet
4...access 2000 or later).
IF you do a update..., either via reordset code, or sql insert statement,
then you can also use
lngLastId = CurrentDb.OpenRecordset("select @@Identity from myTable")(0)