ComboBox.SelStart 屬性 (Access)

SelStart 屬性會指定或決定所選文字的起點或插入點位置若未不選取任何文字。 可讀寫的 Integer

語法

運算式SelStart

表達 代表 ComboBox 物件的變數。

註解

SelStart 屬性使用 Integer 中的範圍為 0 到下拉式方塊的文字方塊部分中的字元總數。

設定或傳回控制項的這個屬性,控制項必須具有焦點。 若要將焦點移到控制項、 使用 SetFocus 方法。

變更 SelStart 屬性會取消選取、 將插入點置於文字中,並將 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 支援與意見反應