Open form to last record

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • awojciehowski
    New Member
    • Feb 2008
    • 21

    #1

    Open form to last record

    I am assuming this is an easy fix but I want to open a form from a switchboard button. I also want the form to automatically open to the last record of that form.

    Any ideas on how I can accomplish this?

    Thanks!
    Adam
  • RuralGuy
    Recognized Expert Contributor
    • Oct 2006
    • 375

    #2
    Always? If so, put this in the OnLoad Event Procedure:
    DoCmd.RunComman d acCmdRecordsGoT oLast

    Comment

    • awojciehowski
      New Member
      • Feb 2008
      • 21

      #3
      RuralGuy-

      Thanks for the script but I am a novice at Access...I am not sure where to place the OnLoad command? I want to click a button from my Switchboard...w here would you recommend me placing the script?

      And yes, this would be all the time that the form would open to the last record.

      Thanks!

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        Highlite and Copy this code:

        Code:
        Private Sub Form_Load()
         DoCmd.RunCommand acCmdRecordsGoToLast
        End Sub
        In Design View for the form to be opened, on the menu
        1. Goto View - Code
        2. Paste the code in
        3. Goto View - Object
        4. Run the form

        Comment

        • awojciehowski
          New Member
          • Feb 2008
          • 21

          #5
          PERFECT!!!

          Thanks for your help!

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            Glad we could help!

            Linq ;0)>

            Comment

            • macderyon
              New Member
              • Feb 2017
              • 1

              #7
              Originally posted by missinglinq
              Highlite and Copy this code:

              Code:
              Private Sub Form_Load()
               DoCmd.RunCommand acCmdRecordsGoToLast
              End Sub
              In Design View for the form to be opened, on the menu
              1. Goto View - Code
              2. Paste the code in
              3. Goto View - Object
              4. Run the form
              Easy way to fix it
              When a form's data entry property is set to yes, it always opens to an empty recordset. As you add records they accumulate and you can scroll forward and back within that set of records. When you close and reopen the form, the form opens to an empty recordset again.

              If you want the second form to show the most recent ("last" has no meaning in database terms since record order is fluid), you need to set the form's data entry property to No and either reference the newest record specifically or do what I said earlier and create a query that sorts the recordset in descending order by date/time entered or autonumber.

              Comment

              Working...