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

SelStart 屬性會指定或決定所選文字的起點或插入點位置若未不選取任何文字。The SelStart property specifies or determines the starting point of the selected text or the position of the insertion point if no text is selected. 可讀寫的 IntegerRead/write Integer.



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


SelStart 屬性使用 Integer 中的範圍為 0 到下拉式方塊的文字方塊部分中的字元總數。The SelStart 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.

變更 SelStart 屬性會取消選取、 將插入點置於文字中,並將 SelLength 屬性設定為 0。Changing the SelStart property cancels the selection, places an insertion point in the text, and sets the SelLength property to 0.


下列範例會使用兩個事件程序來搜尋的使用者所指定的文字。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.