0

I am using VB6.0 for an assignment, it was so long that I used this. I'm trying to get the last inserted Id. My query is giving me the first row ID

I am using OLEDB. I have used some code but it is returning the first-row id.

Network
    rec.Open "staff_profile", con, adOpenDynamic, adLockOptimistic
    With rec
    .AddNew
      ![fields] = values
    .Save
      'rec.Update
  lastID = rec("ID")
  FileCopy frmRegister.cdl.FileName, fname & transcode & ".jpg"
    'return ID
    MsgBox "Record Saved Successfully " & lastID, vbInformation, "Trillium"

I want the result to give me the last inserted id

Krish
  • 5,917
  • 2
  • 14
  • 35
Olizy
  • 41
  • 4
  • 1
    Possible duplicate of [Autonumber value of last inserted row - MS Access / VBA](https://stackoverflow.com/questions/1628267/autonumber-value-of-last-inserted-row-ms-access-vba) – StayOnTarget Jul 08 '19 at 11:11

1 Answers1

2

Try with:

With rec
    .AddNew
      ![fields] = values
    .Save
    .MoveLast
    lastID = !ID.Value
End With
Gustav
  • 53,498
  • 7
  • 29
  • 55