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

您可以使用的 Text 屬性設定或傳回下拉式方塊的文字方塊部分中所包含的文字。You can use the Text property to set or return the text contained in the text box portion of a combo box. 可讀寫 的字串Read/write String.

語法Syntax

運算式文字expression.Text

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

註解Remarks

您可以設定的Text屬性至您想要顯示在控制項中的文字。You can set the Text property to the text that you want to display in the control. 您也可以閱讀文字方塊控制項中目前使用的 Text 屬性。You can also use the Text property to read the text currently in the control.

注意

[!注意事項] 若要設定或傳回控制項的 Text 屬性,控制項必須擁有焦點,或發生錯誤。To set or return a control's Text property, the control must have the focus, or an error occurs. 若要將焦點移到控制項,您可以使用 SetFocus 方法或 GoToControl 巨集指令。To move the focus to a control, you can use the SetFocus method or GoToControl action.

當控制項有焦點時, Text 屬性會包含文字目前控制項中的資料 ; 會在 Value 屬性會包含最後一個控制項的已儲存的資料。While the control has the focus, the Text property contains the text data currently in the control; the Value property contains the last saved data for the control. 當您將焦點移到另一個控制項時,更新控制項資料,並 會在 Value 屬性設為這個新的值。When you move the focus to another control, the control's data is updated, and the Value property is set to this new value. 取得控制項的焦點之前會無法使用 Text 屬性設定值。The Text property setting is then unavailable until the control gets the focus again. 如果您使用 [ 記錄 ] 功能表上的 儲存記錄 ] 命令為控制項中儲存的資料而不將焦點移動, Text 屬性和 Value 屬性設定值會相同。If you use the Save Record command on the Records menu to save the data in the control without moving the focus, the Text property and Value property settings will be the same.

範例Example

下列範例會使用的Text屬性,以啟用名為btnNext ,每當使用者在名為txtName文字方塊中輸入文字的下一步] 按鈕。The following example uses the Text property to enable a Next button named btnNext whenever the user enters text into a text box named txtName. [文字] 方塊是空的只要已停用 [下一步] 按鈕。Anytime the text box is empty, the Next button is disabled.

Sub txtName_Change() 
 btnNext.Enabled = Len(Me!txtName.Text & "")<>0 
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.