Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How do i do rs.movelast

Posted on 2004-11-22
Medium Priority
Last Modified: 2008-03-06

Could someone tell me how to retrieve thgr LAST record in a recordset? Rs.movelast will not work!
Question by:Gonzo84
  • 2
  • 2
LVL 23

Accepted Solution

apresto earned 1840 total points
ID: 12642841
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.
LVL 23

Expert Comment

ID: 12642846
its prob abit long winded but its how i have done it in the past - prob known as a work around :o)

Author Comment

ID: 12642850
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.

LVL 33

Expert Comment

ID: 12642887
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

LVL 33

Expert Comment

ID: 12642901
oops, hadnt refreshed the page.Sorry

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Integration Management Part 2
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month10 days, 13 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question