How do i do rs.movelast

Posted on 2004-11-22
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
    LVL 23

    Accepted Solution

    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

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

    Author Comment

    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

    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

    oops, hadnt refreshed the page.Sorry

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    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…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now