How to Show the Latest Employment History Record in an Access Subform
Question details
The user wants the Employment History subform to automatically jump to and display the most recent entry when the parent employee form loads.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Navigating through employee records in a parent form and needing the linked subform to default to the latest history entry instead of the first one.
- Observed behavior
- The parent form successfully opens to the latest employee record, but the linked subform fails to automatically display the employee's most recent employment history entry.
Ensure you have the exact property names of your subform control and the parent form control where you want the focus to return before editing the VBA code.
Add VBA Code to the Parent Form's Current Event
Use the Code Builder in the parent form's Property Sheet to set focus on the subform, navigate to the last record, and return focus to the main form.
By utilizing the 'On Current' event of the parent form, you can trigger a sequence of actions every time you navigate to a new employee record. The code will briefly switch to the subform to pull up the last chronological record, and then seamlessly return control to your main form.
Right-click your parent form in the Navigation Pane and select Design View. Click on the 'Property Sheet' icon located in the Design tab of the ribbon.
In the Property Sheet, make sure the selection type is set to 'Form'. Navigate to the 'Event' tab, locate the 'On Current' property, click the ellipsis (...) button, and choose 'Code Builder'.
Inside the VBA editor, type: Me.[YourSubformControlName].SetFocus followed by DoCmd.GoToRecord , , acLast on the next line.
Add a final line of code: Me.[ParentControlName].SetFocus to return the cursor to a specific field on your main form. Save the VBA module.
Crucially, replace [YourSubformControlName] and [ParentControlName] with the actual names used in your database, ensuring you use the subform control container's name rather than the original source form's name.

Looking for a Lightweight Office Suite? Try WPS Office
While WPS Office does not directly replace Microsoft Access databases, it serves as a powerful, free alternative to Microsoft Word, Excel, and PowerPoint. It offers an intuitive tabbed interface, lightweight installation, and full compatibility with your existing Office files.
- 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
- 2. Install WPS Office: Run the downloaded installer file and follow the quick on-screen instructions to set up the software.
- 3. Open Your Documents: Launch WPS Office and instantly open your existing Word, Excel, or PowerPoint files without losing any formatting.

Frequently Asked Questions
Why do I get an expression error when the form loads?
This error occurs if the VBA code cannot find the controls specified. Ensure you replaced placeholder names in the script with the exact control names found in your database's Property Sheet.
What is the difference between a subform control name and a source form name?
The source form name is the actual name of the form saved in your database panel. The subform control name is the name given to the specific box (container) that holds that form within the parent form. VBA requires the control name.
Can I show the latest record without using VBA code?
Yes. Alternatively, you can change the subform's Record Source to a query that sorts the employment history dates in descending order. This makes the most recent entry the 'first' record automatically.




