Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Open subform to latest record
Robert Freeman 
      
2 years ago
Hello all. I have a membership database with a main form which incorporates two sub-forms. A new record is created each year in the sub-forms when a member joins or renews. i.e. there is a 2024 record and then there will be a 2025 record.
My question is - how do I get the sub-forms to open at the latest record when the main form is opened. In other words I would like the sub-form(s) to open at the 2025 records.
Juan Rivera  @Reply  
            
2 years ago
several way to get what you like done.  but here is a video which may give you an idea as to how to get this done

New Record on Top
Kevin Robertson  @Reply  
          
2 years ago
I like to have a filter Combo Box on the Parent Form, set the default to the current year and filter the Subform when the Parent Form loads.
Kevin Yip  @Reply  
     
2 years ago
By "open to" or "open at" the latest record, do you mean:
- Show only the latest record on the subform?
- Show all related records in subform, with the latest record on the first row?  Or last row?
- Show all related records in subform, with the latest record selected as the current record?
Gary James  @Reply  
      
2 years ago
I created a Global function in an Access Module that I use to selected an item in a subform after adding or deleting an item.   This is the pertinent code sections.

DetailsPublic Enum FindRecordType

   frtFindByAutonumber
   frtFindFirstRecord
   frtFindLastRecord
   frtFindByOffsetValue
   frtFindByIndexPosition
  
End Enum


DetailsPublic Sub FindFormItem(frm As Form, Optional value As Long = 0, Optional FindType As FindRecordType = FindRecordType.frtFindByAutonumber)
  
   Dim idx As Long
   Dim rs As DAO.Recordset
   Set rs = frm.RecordsetClone
  
   On Error Resume Next
  
   ' if table empty
   If rs.EOF Or rs.BOF Then Exit Sub
  
   Select Case FindType
      Case FindRecordType.frtFindByAutonumber
         rs.FindFirst "ID = " & value
         If (rs.NoMatch = False) Then
            frm.Bookmark = rs.Bookmark
         End If
        
      Case FindRecordType.frtFindFirstRecord
         rs.MoveFirst
         frm.Bookmark = rs.Bookmark
        
      Case FindRecordType.frtFindLastRecord
         rs.movelast
         frm.Bookmark = rs.Bookmark
        
      Case FindRecordType.frtFindByOffsetValue
         rs.MoveFirst
         rs.AbsolutePosition = value
         frm.Bookmark = rs.Bookmark
        
      Case FindRecordType.frtFindByIndexPosition
         idx = value
         If (idx < rs.RecordCount - 1 And idx >= 0) Then
            rs.Move idx
         Else
            rs.Move rs.RecordCount - 1
         End If
         frm.Bookmark = rs.Bookmark
        
   End Select
  
   rs.Close
   Set rs = Nothing

End Sub


To use this function here's the source code from a sub form that calls the above function to select an item in the sub form after adding or deleting an item from the list of items in the form.

DetailsDim sel As Long

Private Sub Form_AfterDelConfirm(Status As Integer)
   On Error Resume Next
   Me.Form.Parent.Requery
   FindFormItem Me.Form, sel, frtFindByIndexPosition
End Sub

Private Sub Form_AfterInsert()
   On Error Resume Next
   Me.Form.Requery
End Sub

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
   On Error Resume Next
   sel = Me.Form.RecordsetClone.AbsolutePosition
End Sub

Private Sub Form_Current()
   On Error Resume Next
   txtSelected = txtID     ' needed to highlite the selected record
   FindFormItem Me.Parent.Form, Nz([txtID], 0), frtFindByAutonumber
End Sub

Robert Freeman OP  @Reply  
      
2 years ago
Thanks everyone.
Firstly - Kevin: It's exactly your last option that I'm trying to achieve (Show all related records in subform, with the latest record selected as the current record?).
Secondly - thanks for all the other ideas - I'll work through them and see what happens. Many thanks for you time and input.
Kevin Yip  @Reply  
     
2 years ago
You can use FindFirst to automatically navigate to the desired record on the subform.  For instance, this code:

     Forms![Main form name]![Subform name].Form.Recordset.FindFirst "[field1] = 2025"

will navigate you to the first record on the subform where field1 equals 2025.

What if a person didn't renew for 2025?  Then you need DMax() to find the year of his most recent renewal.  The most recent year is the maximum value of the year field, hence the use of DMax().  And the code becomes:

     Forms![Main form name]![Subform name].Form.Recordset.FindFirst "[field1] = " & Nz(DMax( ... ), 0)

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/2/2026 5:50:08 AM. PLT: 0s