ComboBox.SelLength 属性 (Access)
SelLength 属性指定或确定在组合框的文本框部分中所选的字符数。 Integer 型,可读/写。
语法
表达式。SelLength
表达 一个代表 ComboBox 对象的变量。
备注
SelLength 属性的值为 Integer 类型,其范围为 0 到组合框的文本框部分中的总字符数。
若要设置或返回控件的这个属性,控件必须获得焦点。 若要将焦点移到某个控件,使用 SetFocus 方法。
将 SelLength 属性设置为一个数字小于 0 将产生运行时错误。
示例
下面的示例使用两个事件过程来搜索用户指定的文本。 要搜索的文本在窗体的 Load 事件过程中设置。 “查找”按钮的 Click 事件过程 (用户单击以开始搜索) 提示用户输入要搜索的文本,并在搜索成功时选择文本框中的文本。
Private Sub Form_Load()
Dim ctlTextToSearch As Control
Set ctlTextToSearch = Forms!Form1!Textbox1
' SetFocus to text box.
ctlTextToSearch.SetFocus
ctlTextToSearch.Text = "This company places large orders twice " & _
"a year for garlic, oregano, chilies and cumin."
Set ctlTextToSearch = Nothing
End Sub
Public Sub Find_Click()
Dim strSearch As String
Dim 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
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。