Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Suffolk, England
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unique ID (VB 6.0)

    I have a adodb recordset. I can update this with data, but the record has a unique ID field which I need to carry forward to another table. I can't seem to get this number into a variable to save it (it returns 0)
    The syntax I am using is as follows:
    strsql = "SELECT * from Tbldata
    with ors
    .Open strsql, oConn, adOpenDynamic, adLockOptimistic, adCmdText
    .AddNew
    ors("DoB") = TxtDoB.Item(0)
    .Update
    DataID = ors("ID")
    End With

    where DataID is the variable I want to hold the ID. Is there some way of refreshing the data without loosing the record position. ID is the primary key
    Thanks

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Unique ID (VB 6.0)

    Recommend see this MSKB article:

    How To Return Record's Autonumber Value Inserted into Access DB

    The code sample provided is VBScript for an ASP page, but uses standard ADO methods that can be adapted for use in Access/VBA so long as you've set a reference to the ADODB type library.

    HTH

  3. #3
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Suffolk, England
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Unique ID (VB 6.0)

    Thanks - I'll give that a go, it looks like just what I need!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •