Get the next ID - Access 2000

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Get the next ID - Access 2000

    I'm sure that this topic is in here somewhere, but I couldn't find it.

    What is the best way to get the next ID in a table when adding a record? I am
    using a MS Access 2000 database. I need to add a record to one table and get
    the autonumber ID to add to a record in another table. I've done this before
    in Oracle using NEXTVAL, but this doesn't work in Access.

    Thanks in advance!

    thamilton44 Guest

  2. Similar Questions and Discussions

    1. problems access an MS Access 2000 DB using ASP
      Our graphic designer is developing our new company website. We have switched providers and currently she is working on the new website which...
    2. Access 2002 PDFWriter VBA Code w/WinXP does not work like Access 2000
      I am trying to print an Access 2002 report (Windows XP OS) as a PDF. I had success with Access 2000 in a Windows 2000 environment, but as soon as I...
    3. Access 2000 or SQL Server 2000
      Hi I am planning to design a database (destined for the web) that will have between 20000 and 45000 records in it and will receive a lot of reads...
    4. ASP for Access 2000
      Hello I have no clue as to how to create asp pages. All I know is that I have placed my Access DB on Brinkster.com and they say I need to be able...
    5. Access 2000 to VB .Net
      Hi, I have a Access 2000 application that I want to transfer to Visual Basic ..Net. I was wondering how I could take my Access 2000 forms, modules...
  3. #2

    Default Re: Get the next ID - Access 2000

    Since you are using autonumber with Access for your ID field, one way to get
    its value is to perform a query immediately after your insert (in a separate
    CFQUERY) to retrieve your ID value.

    SELECT MAX(ID_field)
    FROM your_table....etc.

    It would be a good idea to enclose both cfquiries within cftransaction tags in
    order to guarantee that the ID value that you get was from your insert
    statement, especially if you have a busy site.

    Phil

    paross1 Guest

  4. #3

    Default Re: Get the next ID - Access 2000

    In addition to what Phil said...(enclose the queries in cftransaction)
    the second query can also use: SELECT @@IDENTITY AS LatestID
    HTH,

    --
    Tim Carley
    [url]www.recfusion.com[/url]
    [email]info@NOSPAMINGrecfusion.com[/email]
    Mountain Lover Guest

  5. #4

    Default Re: Get the next ID - Access 2000

    I know SELECT @@IDENTITY AS LatestID works in SQL Server, but I don't think that this is valid in Access, unless something has changed since I last used Access 97.

    Phil
    paross1 Guest

  6. #5

    Default Re: Get the next ID - Access 2000

    It works in Access 2k+...upgrade your version of Access Phil ;-)

    But don't believe me...try it! ;-)

    --
    Tim Carley
    [url]www.recfusion.com[/url]
    [email]info@NOSPAMINGrecfusion.com[/email]
    Mountain Lover Guest

  7. #6

    Default Re: Get the next ID - Access 2000

    Yeah, I used to have an application that used Access 97, but I ported it to SQL
    Server 2k, so I never felt the need to upgrade to Access 2k. Now it is strictly
    Oracle and SQL Server, but I do still have Access 97around to test my answers
    on this forum, just to make sure that I'm not blowing smoke.... :)

    Anyway, that is nice to know, and it looks like MS is making an attempt to
    better align Access with SQL Server.

    Phil

    paross1 Guest

  8. #7

    Default Re: Get the next ID - Access 2000

    Thank you all for your responses. I think the cftransaction is exactly what I was looking for. I'm new to ColdFusion. :)
    thamilton44 Guest

  9. #8

    Default Re: Get the next ID - Access 2000

    I know I ran some tests once to see if cftransaction actually guaranteed that
    the
    max(id) returned following an insert was correct. I think, however, that I
    tried it on
    Access 97 which probably used blunt force locking of the entire table to
    handle
    transaction processing, so it worked. I've subsequently tested using MS SQL
    and since the locking is much more granular, I've found this is not so. The DB
    has no reason to prevent two (almost) simultaneous inserts, so the returned
    Max(ID) value could be wrong. It would be a good idea, if you're using Max(ID)
    to
    include enough criteria, that you just used in the insert, so you get your Max
    ID.

    OldCFer Guest

  10. #9

    Default Re: Get the next ID - Access 2000

    Try looking at this post:


    [url]http://www.macromedia.com/cfusion/webforums/forum/messageview.cfm?catid=7&thread[/url]
    id=978371

    There was a similar problem, though I think that was with MySQL the backend
    shouldn't matter as the theory is the same.

    Another Phil Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139