ComboBox.SelLength 屬性 (Access)ComboBox.SelLength property (Access)

SelLength 屬性會指定或決定下拉式方塊之文字方塊部分中所選取的字元數。The SelLength property specifies or determines the number of characters selected in the text box portion of a combo box. 可讀寫的 IntegerRead/write Integer.



_運算式_代表**ComboBox** 物件的變數。expression A variable that represents a ComboBox object.


SelLength 屬性使用 Integer,其範圍為 0 到下拉式方塊的文字方塊部分中的全部字元數。The SelLength property uses an Integer in the range 0 to the total number of characters in the text box portion of a combo box.

設定或傳回控制項的這個屬性,控制項必須具有焦點。To set or return this property for a control, the control must have the focus. 若要將焦點移到控制項、 使用 SetFocus 方法。To move the focus to a control, use the SetFocus method.

SelLength 屬性設定為小於 0 會產生執行階段錯誤。Setting the SelLength property to a number less than 0 produces a run-time error.


下列範例會使用兩個事件程序來搜尋的使用者所指定的文字。The following example uses two event procedures to search for text specified by a user. 要搜尋的文字是設定在表單的Load事件程序。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.

Private Sub Form_Load() 
 Dim ctlTextToSearch As Control 
 Set ctlTextToSearch = Forms!Form1!Textbox1 
 ' SetFocus to text box. 
 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. 
 .SelStart = intWhere - 1 
 .SelLength = Len(strSearch) 
 ' Notify user. 
 MsgBox "String not found." 
 End If 
 End With 
End Sub

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.