Table of contents

ComboBox.SelText 属性 (访问)ComboBox.SelText Property (Access)

office 365 dev account|上次更新日期: 2018/3/13
2 参与人员

SelText属性将返回包含选定的文本的字符串。读/写,字符串The SelText property returns a string containing the selected text. Read/write String.


表达式SelTextexpression. SelText

表达式_表示组合框对象变量。_expression A variable that represents a ComboBox object.


如果未不选择任何文本, SelText属性将包含一个值。If no text is selected, the SelText property contains a Null value.

SelText属性使用的字符串表达式,包含在控件中选定的文本。如果设置此属性时,控件将包含所选的文本,则新的SelText设置将取代这些文本。The SelText property uses a string expression that contains the text selected in the control. If the control contains selected text when this property is set, the selected text is replaced by the new SelText setting.

若要设置或返回控件的这个属性,控件必须获得焦点。若要将焦点移到某个控件,使用SetFocus方法。To set or return this property for a control, the control must have the focus. To move the focus to a control, use the SetFocus method.


下面的示例使用两个事件过程来搜索用户指定的文本。要搜索的文本在窗体 Load 事件过程中进行设置。“Find”按钮(用户单击后可进行搜索)的 Click 事件过程将提示用户输入要搜索的文本;如果搜索成功,则在文本框中选取该文本。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.SelText = "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. 
 .SelStart = intWhere - 1 
 .SelLength = Len(strSearch) 
 ' Notify user. 
 MsgBox "String not found." 
 End If 
 End With 
End Sub

另请参阅See also


组合框对象ComboBox Object

© 2018 Microsoft