Results 1 to 6 of 6

Thread: Retrieve last row Value from Access Table
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Nov 2011
    Posts
    1,144
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Retrieve last row Value from Access Table

    Hi All

    I have a table called Log which gets updated when something gets updated

    What i want to be able from the Column called Version - i want to retrieve the last row value in that column

    say it says V8

    i want to on workbook open check to see if the value matches the cell value on sheet2!A1 - if it does then fine but if it doesnt then close the workbook saying not in latest version

    hoping you can help me

  2. #2
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,731
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: Retrieve last row Value from Access Table

    The order of records really has no meaning in Access tables (someone once described it as a bag of jumbled marbles).
    You can do an Aggregate Query, to return a record with the oldest/newest date or maximum/minimum value.
    So, is there some field you can use to determine exactly which record you want to return? Maybe some sort of date field?
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  3. #3
    Board Regular
    Join Date
    Nov 2011
    Posts
    1,144
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Retrieve last row Value from Access Table

    Thank you for that explanation

    i didnt have a value to sum but i managed to get the value by ordering it by version number and then selected top 1 from that column

  4. #4
    Board Regular
    Join Date
    Jan 2009
    Posts
    1,164
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Retrieve last row Value from Access Table

    maybe if it has a date column and you know a little vba then do a select query order by date and do a recordset.movelast

  5. #5
    MrExcel MVP
    Junior Admin
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    50,731
    Post Thanks / Like
    Mentioned
    57 Post(s)
    Tagged
    11 Thread(s)

    Default Re: Retrieve last row Value from Access Table

    i didnt have a value to sum but i managed to get the value by ordering it by version number and then selected top 1 from that column
    Aggregate Queries are used for more than just summing!

    I was thinking you could use First/Last or Min/Max on some field.
    See: https://support.office.com/en-us/art...5-8005f1893be5

    i didnt have a value to sum but i managed to get the value by ordering it by version number and then selected top 1 from that column
    The query might look something like this:
    Code:
    SELECT *
    FROM MyTable
    WHERE Version_Number = 
    (SELECT Max(MyTable.Version_Number)
    FROM MyTable);
    maybe if it has a date column and you know a little vba then do a select query order by date and do a recordset.movelast
    You *could* do it this way, but VBA/Recordsets seems to be a bit overkill and unnecessary here. You would still need to Sort/Order the records first, and if you can do that, you can simply use that field in an Aggregate Query instead.
    Last edited by Joe4; Sep 3rd, 2019 at 11:48 AM.
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

  6. #6
    Board Regular
    Join Date
    Jul 2010
    Posts
    446
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Retrieve last row Value from Access Table

    If you have an autonumber or date field then you could also combine Dmax with Dlookup to get the true last. If there is no additions or deletions then DLast will get the last entry.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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