Select All Text in a Microsoft Access Form Control with VBA
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.

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

Reuse the previous entry as a default for new records
Use a default value when repeated entries should appear automatically in new records, or use the keyboard shortcut for occasional copying.
Repair Microsoft Office if valid selection code still fails
Consider installation repair only after checking focus, event timing, and control settings. The reported case was resolved by reinstalling Office.
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.

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.




