Form.Unload 事件 (Access)Form.Unload event (Access)

Unload事件发生在窗体关闭之后、 从屏幕上删除之前。The Unload event occurs after a form is closed but before it's removed from the screen. 窗体重新加载时,Microsoft Access 将重新显示窗体并重新初始化所有控件的内容。When the form is reloaded, Microsoft Access redisplays the form and reinitializes the contents of all its controls.


expressionexpression. Unload( _Cancel_, )

expression:表示 Form 对象的变量。expression A variable that represents a Form object.


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


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

诸如以下的用户操作将引起Unload事件:The Unload event is caused by user actions such as:

  • 关闭窗体。Closing the form.

  • 在宏中运行 Close 操作。Running the Close action in a macro.

  • 通过右键单击应用程序的任务栏按钮,然后单击关闭来退出应用程序。Quitting an application by right-clicking the application's taskbar button and then clicking Close.

  • 在应用程序运行时退出 Windows。Quitting Windows while an application is running.

通过窗体Unload事件发生时运行宏或事件过程,您可以验证应卸载窗体,或指定窗体卸载时应该发生的操作。By running a macro or an event procedure when a form's Unload event occurs, you can verify that the form should be unloaded or specify actions that should take place when the form is unloaded. 您还可以打开另一个窗体或显示一个对话框要求输入用户名称来产生日志项,以表明使用该窗体。You can also open another form or display a dialog box requesting the user's name to make a log entry indicating who used the form.

当关闭窗体时,下列事件将按如下顺序发生:When you close a form, the following events occur in this order:


Unload事件Close事件之前发生。The Unload event occurs before the Close event. Unload 事件可被取消,但不能 关闭 的事件。The Unload event can be canceled, but the Close event can't.

注释 当创建宏或事件过程为相关Unload事件,如停用LostFocus,确保它们不会发生冲突 (例如,确保您不会导致发生一个宏或过程在另一个取消的) 和它们不会导致级联事件。Note When you create macros or event procedures for events related to the Unload event, such as Deactivate and LostFocus, be sure that they don't conflict (for example, make sure you don't cause something to happen in one macro or procedure that is canceled in another) and that they don't cause cascading events.


该示例将提示用户确认窗体是否应该关闭。This example prompts the user to verify that the form should close.

若要试用该示例,请将下列事件过程添加到窗体中。To try the example, add the following event procedure to a form. 在"窗体"视图中,关闭窗体以显示对话框,然后单击"是"或"否"。In Form view, close the form to display the dialog box, and then click Yes or No.

Private Sub Form_Unload(Cancel As Integer) 
 If MsgBox("Close form?", vbYesNo) = vbYes Then 
 Exit Sub 
 Cancel = True 
 End If 
End Sub

另请参阅See also

Form 对象Form Object