Visual Basic Reference

QueryClose Event

See Also    Example    Applies To

Occurs before a form is terminated.

Syntax

Public Sub object_**QueryClose(**cancel As Integer, closemode As Integer)

The QueryClose event syntax has these parts:

Part Description
object Required. An object expression that evaluates to an object in the Applies To list.
cancel Set to any value other than zero to stop the designer from closing.
closemode A value or constant indicating the cause of the QueryClose event, as described in Return Values.

Return Values

The closemode argument returns the following values:

Constant Value Description
vbFormControlMenu 0 The user has chosen the Close command from the Control menu on the designer or clicked the Close button.
vbFormCode 1 The Unload statement is invoked from code.
vbAppWindows 2 The current Windows operating environment session is ending.
vbAppTaskManager 3 The Windows Task Manager is closing the application.
vbFormMDIForm 4 An MDI child form is closing because the MDI form is closing.

Remarks

This event is typically used to make sure there are no unfinished tasks in the designer included in an application before that application closes. For example, if a user hasn't saved new data in any designer, the application can prompt the user to save the data.

When an application closes, you can use the QueryClose event procedure to set the Cancel property to True, stopping the closing process.