Results 1 to 10 of 10
  1. #1
    rwahdan1978 is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    57

    Thumbs up When startup check for last record

    Hi,



    When I start my switchboard (main page) I need to check a table for the last record (row) programatically, how to do that?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    How do you determine last row? autonumber, date/time ?
    DMAX() would get you a field or several. If you need more than two or 3, I would use a recordset and perhaps a SELECT TOP 1 and order as needed.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  4. #4
    rwahdan1978 is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    57
    after making a new record it is saved last in the table, how to access last record in a table programatically?

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Quote Originally Posted by rwahdan1978 View Post
    after making a new record it is saved last in the table, how to access last record in a table programatically?
    If you have incremental autonumber, then that would be the last record added to the table.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Records are stored in a table in no specific order-- very much like marbles in a bag. Order of retrieval/selection is based on a query "Order BY" clause. We need to know what LAST means to you to provide more focused response.

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    how to access last record in a table programatically?
    Merely repeating your requirement over and over again is not helpful.
    What data within the record itself defines that it is the last? A date? an Invoice Number? A primary key value?
    You cannot reliably and consistently use the position of the record in the table to determine if it is the last.

  8. #8
    rwahdan1978 is offline Advanced Beginner
    Windows 11 Access 2016
    Join Date
    Jun 2024
    Posts
    57
    Dim rs As Recordset

    Set rs = CurrentDb.OpenRecordset("SELECT TOP 1 * FROM Turns ORDER BY ID DESC")
    MsgBox ("Last Turn: " & rs!Person & " On " & rs!TheTime)
    rs.Close
    Set rs = Nothing

  9. #9
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Make the recordsource for the form a query string.

    "Select * from turns order by ID DESC"

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,566
    Best to always qualify your objects.

    Code:
    Dim rs As DAO.Recordset
    
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 07-21-2023, 10:27 AM
  2. Replies: 1
    Last Post: 09-27-2020, 04:42 AM
  3. Replies: 5
    Last Post: 08-18-2018, 10:23 AM
  4. Check if record exists, Check Number
    By burrina in forum Forms
    Replies: 9
    Last Post: 01-06-2013, 03:49 PM
  5. Replies: 3
    Last Post: 10-19-2012, 04:30 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums