Posted by rkc on 04/14/06 01:13
Rico wrote:
> Thanks Tom and Erland,
>
> I wound up researching Scope_Identity and that lead me to @@identity. I
> wound up changing my DAO code as follows;
>
> Instead of....
>
> dim MyNewID as long
> set rst = db.OpenRecordset("MyTable")
> rst.AddNew
> rst!MyTextfield="My New Text"
> MyNewID=rst!IDfield ' (this is the autonum field from the previous Access
> db)
> rst.Update
>
>
> I changed the code to
>
> dim MyNewID as long
> set rst = db.OpenRecordset("MyTable")
> rst.AddNew
> rst!MyTextfield="My New Text"
> rst.Update
>
> MyNewID=db.OpenRecorset("SELECT @@Identity").Fields(0)
If you use an ADODB.Recordset with the correct property settings
the the new record will be added to the recordset you have open
and the newly added record will be the current record.
[Back to original message]
|