Table of contents
TOC
折叠目录
展开目录

OptionButton.Exit 事件 (访问)OptionButton.Exit Event (Access)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

从一个控件转移到同一窗体或报表上另一个控件焦点之前,发生Exit事件。The Exit event occurs just before a control loses the focus to another control on the same form or report.

语法Syntax

表达式退出(* 取消)expression. **Exit( ** Cancel* )

表达式_一个表示一个选项按钮对象的变量。_expression A variable that represents an OptionButton object.

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
CancelCancel必需RequiredIntegerInteger设置为True以取消该事件。Set to True to cancel the event.

注解Remarks

该事件不适用于选项组中的复选框、选项按钮或切换按钮。它仅适用于选项组本身。This event does not apply to check boxes, option buttons, or toggle buttons in an option group. It applies only to the option group itself.

若要在该事件发生时运行宏或事件过程,请将OnExit属性设置为宏的名称或 [事件过程]。To run a macro or event procedure when this event occurs, set the OnExit property to the name of the macro or to [Event Procedure].

因为在焦点移动到一个指定控件之前,发生Enter事件,所以可以使用Enter宏或事件过程来显示说明。例如,可以使用宏或事件过程显示一个小的窗体或消息框,以指出控件通常包含,数据的类型,或给出如何使用控件的说明。Because the Enter event occurs before the focus moves to a particular control, you can use an Enter macro or event procedure to display instructions; for example, you could use a macro or event procedure to display a small form or message box identifying the type of data the control typically contains, or giving instructions on how to use the control.

LostFocus事件之前,发生Exit事件。The Exit event occurs before the LostFocus event.

LostFocus事件中,不同窗体失去焦点时不会退出事件。例如,假定您选择窗体上的复选框,然后单击报表。当您选择复选框时,会发生EnterGotFocus事件。当您单击该报表仅LostFocus事件发生。(因为焦点移动到其他窗口),则不会发生Exit事件。如果您选择再次要将它显示为前台的窗体上的复选框, GotFocus事件发生,但不是Enter事件 (因为上次活动窗体时,该控件具有焦点)。只有在单击窗体上的另一个控件时,将发生Exit事件。Unlike the LostFocus event, the Exit event does not occur when a form loses the focus. For example, suppose you select a check box on a form, and then click a report. The Enter and GotFocus events occur when you select the check box. Only the LostFocus event occurs when you click the report. The Exit event doesn't occur (because the focus is moving to a different window). If you select the check box on the form again to bring it to the foreground, the GotFocus event occurs, but not the Enter event (because the control had the focus when the form was last active). The Exit event occurs only when you click another control on the form.

如果将焦点移到窗体上的控件,该控件不具有焦点,该窗体上,在窗体具有焦点的控件的ExitLostFocus事件发生之前的EnterGotFocus事件移动到的控件。If you move the focus to a control on a form, and that control doesn't have the focus on that form, the Exit and LostFocus events for the control that does have the focus on the form occur before the Enter and GotFocus events for the control you moved to.

如果使用鼠标将焦点从主窗体上的控件移动到该窗体的子窗体上的控件(子窗体上没有获得焦点的控件),将发生下列事件:If you use the mouse to move the focus from a control on a main form to a control on a subform of that form (a control that doesn't already have the focus on the subform), the following events occur:

退出(对于主窗体上的控件)Exit (for the control on the main form)

?

LostFocus(对于主窗体上的控件)LostFocus (for the control on the main form)

?

输入(用于子窗体控件)Enter (for the subform control)

?

退出(适用于具有焦点的窗体控件)Exit (for the control on the subform that had the focus)

?

LostFocus(适用于具有焦点的窗体控件)LostFocus (for the control on the subform that had the focus)

?

输入(对于在焦点移到子窗体控件)Enter (for the control on the subform that the focus moved to)

?

GotFocus(对于在焦点移到子窗体控件)GotFocus (for the control on the subform that the focus moved to)

如果该控件移到子窗体上以前具有焦点时,其输入事件和其GotFocus事件都不会发生,但发生子窗体控件的输入事件。如果将焦点从子窗体上的控件移到主窗体上的控件时,子窗体上的控件的ExitLostFocus事件不会发生,刚子窗体控件的EnterGotFocus 的退出事件在主窗体上控件的事件。If the control you move to on the subform previously had the focus, neither its Enter event nor its GotFocus event occurs, but the Enter event for the subform control does occur. If you move the focus from a control on a subform to a control on the main form, the Exit and LostFocus events for the control on the subform don't occur, just the Exit event for the subform control and the Enter and GotFocus events for the control on the main form.

请注意 一般使用鼠标或如选项卡上的某个键以将焦点移到另一个控件。这会导致鼠标或键盘,还在本主题讨论的事件将发生的事件。Note You often use the mouse or a key such as TAB to move the focus to another control. This causes mouse or keyboard events to occur in addition to the events discussed in this topic.

示例Example

在下面的示例中,两个事件过程附加到姓氏文本框中。Enter事件过程显示一条消息,指定的数据类型的用户可以输入的文本框中。Exit事件过程显示一个对话框询问用户如果保存者应将焦点移动到另一个控件。如果用户单击取消按钮, Cancel_参数设置为True (?1),其功能是将焦点移到文本框而不保存更改。如果用户选择确定按钮,保存所做的更改,并在焦点移到另一个控件。In the following example, two event procedures are attached to the LastName text box. The Enter event procedure displays a message specifying what type of data the user can enter in the text box. The Exit event procedure displays a dialog box asking the user if changes should be saved before the focus moves to another control. If the user clicks the Cancel button, the _Cancel argument is set to True (?1), which moves the focus to the text box without saving changes. If the user chooses the OK button, the changes are saved, and the focus moves to another control.

若要尝试运行该示例,请将以下事件过程添加到包含名为 LastName(姓氏)文本框的窗体上。To try the example, add the following event procedure to a form that contains a text box named LastName.

Private Sub LastName_Enter() 
 MsgBox "Enter your last name." 
End Sub 

Private Sub LastName_Exit(Cancel As Integer) 
 Dim strMsg As String 

 strMsg = "You entered '" &; Me!LastName _ 
 &; "' as your last name." &; _ 
 vbCrLf &; "Is this correct?" 
 If MsgBox(strMsg, vbYesNo) = vbNo Then 
 Cancel = True ' Cancel exit. 
 Else 
 Exit Sub ' Save changes and exit. 
 End If 
End Sub

另请参阅See also

概念Concepts

OptionButton 对象OptionButton Object

© 2018 Microsoft