How to Set Focus to the Previous Field After Moving Records in Access
Question details
The user wants to restore the cursor focus to the previously active input field after clicking a custom record navigation button.
- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Navigating through records using custom form buttons while actively editing data fields.
- Observed behavior
- Clicking the navigation button makes the button itself the active control, losing the focus on the data entry field. Assigning the control's name to a variable causes an 'Object required' error.
Ensure you have a backup of your database and that your form is opened in Design View so you can safely edit the VBA code behind the navigation buttons.
Use Screen.PreviousControl in VBA
Capture the previously active control into a variable before the record changes, then restore focus to it after the transition.
When you click a custom navigation button in an Access form, the button takes focus. To send the focus back to the field you were just editing, you must use the Screen.PreviousControl property.
It is crucial to assign the actual Control object to your variable, not the control's name as a string, to avoid 'Object required' runtime errors.
In Access, open your form in Design View. Right-click your custom navigation button (e.g., cmdNext) and select 'Build Event', then choose 'Code Builder'.
Inside the Click event procedure, declare a variable to hold the control object by typing: Dim previousControl As Control.
Assign the previously active field to your variable using the Set keyword: Set previousControl = Screen.PreviousControl. Do not append '.Name' to the property.
Add 'On Error Resume Next' to prevent crashes if the previous control is unable to receive focus (for example, if it is disabled or locked).
Execute the navigation command (e.g., DoCmd.GoToRecord , , acNext) and immediately restore focus by calling previousControl.SetFocus.

Experience a Lighter, Faster Office Suite with WPS Office
While Microsoft Access requires complex VBA coding for custom database behaviors, handling your daily documents, spreadsheets, and presentations shouldn't be complicated. WPS Office provides a free, lightweight, and incredibly intuitive alternative for all your core office tasks.
- 1. Download the Installer: Visit the official WPS Office website and download the free installation package for your operating system.
- 2. Install the Suite: Run the installer and follow the simple on-screen instructions to set up WPS Office on your device.
- 3. Open and Edit Your Files: Launch WPS Office to instantly open and edit your existing Word, Excel, and PowerPoint files without any formatting loss.

Frequently Asked Questions
Why do I get an 'Object required' error when trying to save the active control?
This happens if you try to assign the control's name (a text string) to a variable declared as a Control object. For example, using 'Set myControl = Screen.ActiveControl.Name' causes this error. You must assign the object itself by omitting '.Name'.
Can I use this VBA code for a 'Previous Record' button?
Yes, the exact same logic applies to any navigation button. Simply replace 'acNext' with 'acPrevious' in the 'DoCmd.GoToRecord' statement to move backward through your records while maintaining focus.
What if the previous control is read-only or hidden?
If the previous control cannot accept focus due to being hidden or disabled, the 'SetFocus' method will fail. Including 'On Error Resume Next' right before your navigation and focus commands ensures the code continues running without crashing.




