Others

Select All Text in a Microsoft Access Form Control with VBA

Ayan MasoodAyan Masood Nov 13, 2026 869 views

Question details

The user wants to suggest a value from the previous record in an Access form text box and select the entire value so that typing replaces it.

Select All Text in a Microsoft Access Form Control with VBA
Product
Microsoft Access for Microsoft 365
Device & OS
not provided
Scenario
An Access form reuses a previous record's value as a suggestion that the user can either keep or overwrite.
Observed behavior
VBA attempts using SelStart, SelLength, and SelText do not select the control contents as expected.
Before you start

Open the form in Design View and check the text box's Name property; use that name rather than its label in VBA. Confirm that the text box is enabled, unlocked, and able to receive focus.

Solution 1Recommended

Select the text after the Access text box receives focus

Use this method when a suggested value is already displayed and new typing should replace the entire value.

SelStart and SelLength control the highlighted range. SelText reads or replaces selected text; it does not create a selection. Give the text box focus before accessing its Text property or setting its selection.

1
Open the Got Focus event

In Design View, select the text box and open Property Sheet > Event > On Got Focus. Choose [Event Procedure], then click the ellipsis button to open the VBA editor.

2
Add the selection code

Replace ControlName with the text box's actual name and use: Private Sub ControlName_GotFocus() With Me.ControlName .SelStart = 0 .SelLength = Len(Nz(.Text, "")) End With End Sub

3
Apply selection after assigning a suggestion

If your existing VBA copies the previous value into the text box, place the selection code after that assignment: Me.ControlName.SetFocus Me.ControlName.SelStart = 0 Me.ControlName.SelLength = Len(Nz(Me.ControlName.Text, "")) This also handles cases where the text box already has focus and Got Focus does not run again.

4
Test replacement in Form View

Save the form, switch to Form View, and navigate to the record where the suggestion appears. Tab into the text box and type a replacement. Test keyboard navigation first, because clicking inside the text box can reposition the insertion point after focus changes.

Select the text after the Access text box receives focus
Selecting text does not save a record: These properties only change the highlighted text. Your existing record-saving and validation logic still determines whether the suggested or replacement value is stored.
Free Microsoft Office alternative

Use WPS Office for documents and spreadsheets alongside Access

WPS Office is a free, lightweight alternative for everyday documents, spreadsheets, and presentations. Its familiar interface and Microsoft Office format compatibility make migration straightforward for supported files. It does not replace Microsoft Access or repair Access form-control VBA behavior.

Free tools for document, spreadsheet, and presentation tasksCompatible with Microsoft Word .docx, Excel .xlsx, and PowerPoint .pptx formatsFamiliar interface for an easy transition from common Office workflowsUseful for working with Access data exported to supported spreadsheet formats, without replacing Access forms or database logic
microsoft office alternative - wps office

Frequently Asked Questions

Why does SelText not select all the text in my Access text box?

SelText reads or replaces the currently selected text. To highlight the whole value, give the text box focus, set SelStart to 0, and set SelLength to Len(Nz(Me.ControlName.Text, "")).

Which event should I use to highlight a suggested value?

Use the text box's On Got Focus event when selection should occur as the user enters the control. If VBA assigns the suggestion while the control already has focus, set SelStart and SelLength immediately after the assignment instead.

Can I copy the previous record's value without writing VBA?

Yes. In Form View, place the cursor in the destination field and press Ctrl+quotation mark (Ctrl+"). Access inserts that field's value from the previous record in the current record order.

Will changing DefaultValue overwrite existing records?

No. A control's DefaultValue supplies a value for new records; it does not update existing records. Set it in the control's After Update event if the latest entry should become the next new record's suggestion.

Can WPS Office run my Access forms and VBA selection code?

No. WPS Office does not run Access database forms or their VBA events. Keep using Microsoft Access for this task; WPS Spreadsheets can be used separately for Access data exported to supported spreadsheet formats.