ComboBox.SetFocus 方法 (Access)ComboBox.SetFocus method (Access)

SetFocus 方法會將焦點移至指定的表單、 作用中表單上指定的控制項或作用中資料工作表上指定的欄位。The SetFocus method moves the focus to the specified form, the specified control on the active form, or the specified field on the active datasheet.

語法Syntax

運算式SetFocusexpression.SetFocus

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

傳回值Return value

Nothing

註解Remarks

您可以使用 SetFocus 方法時您想要特定的欄位或控制項擁有焦點,讓所有使用者的輸入都會導入至此物件。You can use the SetFocus method when you want a particular field or control to have the focus so that all user input is directed to this object.

若要讀取的某些控制項的屬性,您需要確定控制項有焦點。To read some of the properties of a control, you need to ensure that the control has the focus. 例如,文字方塊必須焦點之前可以讀取其 文字 屬性。For example, a text box must have the focus before you can read its Text property.

只有當控制項沒有焦點時,您可以將其他屬性。Other properties can be set only when a control doesn't have the focus. 例如,您無法設定控制項的 VisibleEnabled 屬性設為 False (0) 當控制項有焦點。For example, you can't set a control's Visible or Enabled properties to False (0) when that control has the focus.

您也可以使用 SetFocus 方法來瀏覽根據特定條件表單中。You can also use the SetFocus method to navigate in a form according to certain conditions. 例如,如果第一個的問題會統計的問卷表單上的一組使用者選取 不適用 ,Visual Basic 程式碼可能會再自動略過該集合中的問題和將焦點移到問題的下一個集中的第一個控制項。For example, if the user selects Not applicable for the first of a set of questions on a form that's a questionnaire, your Visual Basic code might then automatically skip the questions in that set and move the focus to the first control in the next set of questions.

您只能將焦點移動至看得見的控制項或表單。You can move the focus only to a visible control or form. 完成表單的Load事件之前,表單及表單上的控制項不可見。A form and controls on a form aren't visible until the form's Load event has finished. 因此,如果您在表單的Load事件中使用SetFocus方法將焦點移到該表單時,您必須使用Repaint方法之前SetFocus方法。Therefore, if you use the SetFocus method in a form's Load event to move the focus to that form, you must use the Repaint method before the SetFocus method.

您無法將焦點移至控制項,如果其 Enabled 屬性設為 FalseYou can't move the focus to a control if its Enabled property is set to False. 之前將焦點移至該控制項,您必須設定控制項的Enabled屬性為True (1)。You must set a control's Enabled property to True (1) before you can move the focus to that control. 您可以,但將焦點移至控制項如果其 Locked 屬性設為 TrueYou can, however, move the focus to a control if its Locked property is set to True.

如果表單包含 Enabled 屬性設定為 True 的控制項,您無法將焦點移至表單本身。If a form contains controls for which the Enabled property is set to True, you can't move the focus to the form itself. 您只能移動焦點移至表單上的控制項。You can only move the focus to controls on the form. 在此例中,如果您嘗試使用 SetFocus 焦點移至表單,將焦點設置為最後一個接收焦點的表單上的控制項。In this case, if you try to use SetFocus to move the focus to a form, the focus is set to the control on the form that last received the focus.

您可以使用 SetFocus 方法將焦點移至子表單中,這是一種控制項。You can use the SetFocus method to move the focus to a subform, which is a type of control. 您可以也將焦點移至子表單控制項使用 SetFocus 方法兩次,先將焦點移到子表單,然後在子表單中的控制項。You can also move the focus to a control on a subform by using the SetFocus method twice, moving the focus first to the subform and then to the control on the subform.

範例Example

下列範例使用SetFocus方法Employees ] 表單上將焦點移至 [ EmployeeID ] 文字方塊中。The following example uses the SetFocus method to move the focus to an EmployeeID text box on an Employees form.

Forms!Employees!EmployeeID.SetFocus

支援和意見反應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.