How do i do rs.movelast


Could someone tell me how to retrieve thgr LAST record in a recordset? Rs.movelast will not work!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Order your recordset by DESC (...ORDER BY myfield DESC") and do this:


Dim tempi

If not rs.eof Then
            tempi = rs("ID")
End if

Dim defaultnum
defaultnum = tempi + 1

response.write defaultnum


Default num is the value of the next number that will be generated, tempi is the number of the last ID in the recordset, you can do this for different fields but the + 1 will only work on integer fields obviously.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
its prob abit long winded but its how i have done it in the past - prob known as a work around :o)
Gonzo84Author Commented:
Works for me.  it is actually an ID field i need to find out as i am creating a form online so the user can add a new record to the db and i created the db form a spreadsheet so i couldnt use autonumber, hence why i needed to know hwo to generate the next number.

If you just want to retrieve the last record. you could also try this
<% Response.Buffer = True %>
    Dim rs
        Set rs = Server.CreateObject ("ADODB.Recordset")
'    strExecute = "SELECT * FROM members"
'    rs.Open strExecute, cnn, 3
    rs.Open "members", "DSN=odbc_exmp" ,2
     rs.movelast  'note this code
    While Not rs.EOF
        Response.Write "First Name : " & rs("firstname") & "<br>"
        Response.Write "Last Name : " & rs("lastname") & "<br>"
        Response.Write "<br>"
    Set rs = Nothing

oops, hadnt refreshed the page.Sorry
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.