Results 1 to 5 of 5
  1. #1
    sleake is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    51

    Access Form Does Not Open to Last Record - Opens to Earliest Record


    I put the following code in the On Load event of this form: DoCmd.RunCommand acCmdRecordsGoToLast
    It opens with records created in March 2014 at record 46, and ends with records created in December 2014, at record 1, using the navigation buttons. I've compacted the database, decompiled the code, and recompiled. I really need to have the form open to the most recent record.

    Any suggestions?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    If you want the latest(Date) record, then use a query that specifically looks for Max(datefield)
    [code
    SELECT your fields FROM yourtable
    WHERE someDateField = (SELECT Max(someDateField) FROM yourtable)
    [/code]

    There is no order to records in a table. If you delete a record, that space could be used by another record.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Do you have descending date sort order set on the form?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by June7 View Post
    Do you have descending date sort order set on the form?
    That certainly sounds like the problem!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    sleake is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    51

    Smile

    I tried setting the Order By on the form to descending on the create date (entered automatically) and the auto-numbered ID, and another date field. None worked. So I went to another database I created where it does go to the last record of over a thousand records.

    Code:
    Private Sub Form_Load()
     
        DoCmd.GoToRecord , , acLast
       
    End Sub
    That didn't work until I deleted the Order By line in this database, and voila, opens to last record. The Order By line was obviously conflicting with the "go to last code" I stated in the first post.

    I appreciate your responses. Don't know why the Order By doesn't work, but am happy with the solution. The first solution offered did go to the last record, but filtered by the Where clause. I need to be able to page back a few previous records to record certain information.

    Thanks for your time and generosity.

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

Similar Threads

  1. Replies: 13
    Last Post: 07-24-2014, 04:30 PM
  2. Form always opens to new record
    By gemadan96 in forum Forms
    Replies: 1
    Last Post: 07-22-2014, 06:17 AM
  3. Replies: 3
    Last Post: 11-01-2013, 10:16 AM
  4. Replies: 2
    Last Post: 03-13-2013, 06:13 PM
  5. Replies: 3
    Last Post: 08-26-2012, 10:04 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