logo
search
Others

How to Show the Latest Employment History Record in an Access Subform

Ayan MasoodAyan Masood Sep 28, 2026 869 views

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.

How to Show the Latest Employment History Record in an Access Subform
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Form Design View

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.

2
Access the Code Builder

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'.

3
Write the Navigation Code

Inside the VBA editor, type: Me.[YourSubformControlName].SetFocus followed by DoCmd.GoToRecord , , acLast on the next line.

4
Return Focus to the Parent Form

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.

5
Replace Placeholder Names

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.

Add VBA Code to the Parent Form's Current Event
Avoiding Expression Errors: If you receive an expression error after saving, it usually means a placeholder name was left in the code. Double-check your control names in the Property Sheet.
Free Microsoft Office alternative

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. 1. Download the Installer: Visit the official WPS Office website and click the free download button for your operating system.
  2. 2. Install WPS Office: Run the downloaded installer file and follow the quick on-screen instructions to set up the software.
  3. 3. Open Your Documents: Launch WPS Office and instantly open your existing Word, Excel, or PowerPoint files without losing any formatting.
Completely free to use with a highly intuitive, user-friendly interface.Fully compatible with Microsoft Word, Excel, and PowerPoint file formats (.docx, .xlsx, .pptx).Lightweight application that uses minimal system resources.Built-in PDF editing, conversion, and splitting tools.
QA img-9

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.