
Recordset value changes with .update
I'm no expert, but I believe you'll find that .AddNew ... .Update creates a
new record but doesn't move to it. Depending on whether the recordset is a
dynaset or a table-type recordset with an index, the record is created
either at the end of the recordset or in the position defined by the key.
Between .AddNew and .Update, the record you're dealing with is the new
record you're creating; however, after .Update the current record is the
same one you were looking at before you executed .AddNew.
In the example you gave, with an ascending autonumber primary key in a
table-type recordset table, the new record is created at the end of the
recordset because the key places it there. Therefore, after the .Update,
.MoveLast will position the recordset at the newly-created record.
--
Dirk Goldgar
(to reply via email, remove NOSPAM from address)
Quote:
>If a table has an autonumber ID field and the following code segment is run
>in Access 2000:
>Public Sub test()
>Set db = Currentdb
>Set rs = db.OpenRecordset("tblTest")
>rs.AddNew
>Debug.Print rs![ID]
>rs.Update
>Debug.Print rs![ID]
>rs.MoveLast
>Debug.Print rs![ID]
>rs.Close
>End Sub
>I get the correct value for ID for the first and third Debug.Prints, but
>just after the .Update, the value changes to an already existing previous
>record. Why is that? Shouldn't the current record still be the same after a
>.Update unless I move to another record? Why do I have to do a .MoveLast to
>point to the record I just updated?
>Thanks for any help,
>Dom