Results 1 to 3 of 3

Thread: Find Last Line

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    146

    Find Last Line

    Can U Just Tell Me The Query To Get A Field From The Last Line Of The Table From Access Data Base

  2. #2
    Hyperactive Member
    Join Date
    Apr 2004
    Posts
    342

    Re: Find Last Line

    Gets the First/Top:
    select top 1 * from TABLE_NAME

    Gets the Last:
    select top 1 * from TABLE_NAME order by FIELD_NAME desc

    This is all relative to the Order By though.... You need to have a primary key that you can sort on....

  3. #3
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: Find Last Line

    You can use MoveLast

    VB Code:
    1. Option Explicit
    2.  
    3. Private objConn As ADODB.Connection
    4. Private objRs As ADODB.Recordset
    5.  
    6. Private Sub OpenDBConnection()
    7.     Set objConn = New ADODB.Connection
    8.     objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\myFile.Mdb"
    9. End Sub
    10.  
    11. Private Sub CloseDBConnection()
    12.     If Not objConn Is Nothing Then
    13.         If objConn.State = adStateOpen Then objConn.Close
    14.         Set objConn = Nothing
    15.     End If
    16. End Sub
    17.  
    18. Private Sub Command1_Click()
    19.     Dim rsSql As String
    20.     OpenDBConnection
    21.     Set objRs = New ADODB.Recordset
    22.     rsSql = "Select * FROM myTable"
    23.     objRs.Open rsSql, objConn, adOpenStatic, adLockReadOnly, adCmdText
    24.     If Not objRs.EOF Then
    25.         objRs.MoveLast
    26.         Debug.Print objRs("name")
    27.     End If
    28.     objRs.Close
    29.     Set objRs = Nothing
    30.     CloseDBConnection
    31. End Sub
    Last edited by rory; Aug 22nd, 2006 at 07:26 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width