Web Analytics Made Easy -
StatCounter anopther requery error - CodingForum

Announcement

Collapse
No announcement yet.

anopther requery error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • anopther requery error

    Hi again once more i am stumped by using addnew and requery to get the autoid of the entered record. last time was the bookmark and requery stopped working after 3 months of working fine...just stopped one day and refused to start as seen here..

    http://www.codingforum.net/showthread.php?t=95954

    now i have another page using the exact same code but the bookmark and requery is now giving me the autoid of the 2nd last entered record

    here is the database (autonumber 'jobid' on the left & lnginteger 'clientid' on the right) - i just entered record for client with id 151 and autonumber assigned in access 2003 was as can be seen 129 (for the corresponding jobid to client id)




    I use this code:


    strSQL = "SELECT * FROM clientjob"


    objRs.Open strSQL, objConn, 3, 3

    objRs.AddNew

    objRs.Fields("clientid") = LngClientID


    objRs.Update


    bookmark = objRS.absolutePosition
    objRS.Requery
    objRS.absolutePosition = bookmark ' change cursor back

    ' Autonumber value
    LngJobID = objRS("jobid")

    response.Write "jobid4&nbsp;&nbsp;" & (LngJobId) & "<br>"


    and the result of the jobid of the autonumber?

    128

    am i being really stupid or is something weird going on?
    I have a few problems with this (all my) code (sloppy written as a novice but most of this works for a friends needs - but these things are really driving me crazy and i cant find anyone else with same problems.


    as last problem shown on thread mentioned above which suddenly stopped working i have changed code from:

    strSQL = "SELECT * FROM clientjob"


    objRs.Open strSQL, objConn, 3, 3

    objRs.AddNew

    objRs.Fields("clientid") = LngClientID


    objRs.Update


    bookmark = objRS.absolutePosition
    objRS.Requery
    objRS.absolutePosition = bookmark ' change cursor back

    ' Autonumber value
    LngJobID = objRS("jobid")


    to simply:

    strSQL = "SELECT * FROM clientjob"


    objRs.Open strSQL, objConn, 3, 3

    objRs.AddNew

    objRs.Fields("clientid") = LngClientID


    objRs.Update

    ' Autonumber value
    LngJobID = objRS("jobid")

    and my results are now right? whyyyyyyyyyyyy?

    or at least they are so far until the nightmare starts again......
    Last edited by skalag; Sep 27, 2006, 06:42 PM. Reason: edited due to change in results with code change
    ska

  • #2
    It's not all that helpful an answer, I know, but I never worked out why people use AddNew. Just get your connection to execute a SQL INSERT. The idea of starting a row insertion with a SELECT seems doomed to... woe.

    Comment


    • #3
      yes i think youre right, im definitely going to learn the best ways to do this because ive had too many strange results using this practice, though on the up side i seem to have all my problems sorted out for now. Time to redo it all in a better way now before i get any more woe.......

      thanks
      ska

      Comment


      • #4
        I would also recommend that you use SQL queries.
        Try this http://www.kamath.com/tutorials/tut007_identity.asp
        http://www.degs.co.uk
        http://www.computer-helpforum.com

        Comment

        Working...
        X