Applies To Combo Box control, Text Box control.
Description
You can use these properties for tasks such as positioning the insertion point, establishing an insertion range, selecting parts of strings in a text box or combo box control, and deleting text.
Setting
You can set the SelLength and SelStart properties by using a macro or Visual Basic. The SelText property is read-only.
See Also SetFocus method, Text property.
Example The following example uses two event procedures to search for text specified by a user. The text to search is set in the form's Load event procedure. The Click event procedure for the Find button (which the user clicks to start the search) prompts the user for the text to search for and selects the text in the text box if the search is successful.Sub Form_Load()
Dim ctlTextToSearch As Control
Set ctlTextToSearch = Forms!Form1!TextBox1
ctlTextToSearch.SetFocus ' SetFocus to text box.
ctlTextToSearch.Text = "This company places large orders " _
& "twice a year for garlic, oregano, chilies and cumin."
End Sub
Sub Find_Click()
Dim strSearch As String, intWhere As Integer
Dim ctlTextToSearch As Control
' Get search string from user.
With Me!Textbox1
strSearch = InputBox("Enter text to find:")
' Find string in text.
intWhere = InStr(.Value, strSearch)
If intWhere Then
' If found.
.SetFocus
.SelStart = intWhere - 1
.SelLength = Len(strSearch)
Else
' Notify user.
MsgBox "String not found."
End If
End With
End Sub