logo
search
Others

How to Set Focus to the Previous Field After Moving Records in Access

Ayan MasoodAyan Masood Sep 25, 2026 869 views

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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

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

2
Declare the Control Variable

Inside the Click event procedure, declare a variable to hold the control object by typing: Dim previousControl As Control.

3
Store the Previous Control

Assign the previously active field to your variable using the Set keyword: Set previousControl = Screen.PreviousControl. Do not append '.Name' to the property.

4
Add Error Handling

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

5
Navigate and Restore Focus

Execute the navigation command (e.g., DoCmd.GoToRecord , , acNext) and immediately restore focus by calling previousControl.SetFocus.

Use Screen.PreviousControl in VBA
Avoid the 'Object Required' Error: If you use 'Screen.ActiveControl.Name' or 'Screen.PreviousControl.Name', VBA returns a text string. Since your variable is dimensioned as a Control object, assigning a string to it will trigger an 'Object required' error.
Free Microsoft Office alternative

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. 1. Download the Installer: Visit the official WPS Office website and download the free installation package for your operating system.
  2. 2. Install the Suite: Run the installer and follow the simple on-screen instructions to set up WPS Office on your device.
  3. 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.
Seamless compatibility with Microsoft Office formats (.docx, .xlsx, .pptx)Lightweight design that runs quickly on devices with lower specificationsFamiliar tabbed interface that requires zero learning curveBuilt-in PDF editor for reading, converting, and editing PDF files easily
microsoft office alternative - wps office

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.