I want a certain subroutine to run if the user clicks the red close button in the top corner of the form.

Is there a subroutine similar to Form_Load() when the form is opened that will do this for me?

Thanks in advance

However, the query unload event is fired before the unload and terminate events and this event will be able to tell you how and why your form is closing...

Good Luck

Hi,
Use the below code.

Private Sub Form_Unload(Cancel as Integer)
Msgbox "This form will close because you have clicked Close button on control box.", vbOKonly
End Sub

Above example will display message when you clicked the close button.

Hope this helps.

Hi,
Use the below code.

Private Sub Form_Unload(Cancel as Integer)
Msgbox "This form will close because you have clicked Close button on control box.", vbOKonly
End Sub

Above example will display message when you clicked the close button.

Hope this helps.

What happens if you click the exit button which is supposed to close the form ? Or execute the statement Form.unload ?
Think again. Or actually, read the posts in this thread...

This question has already been answered. Start a new discussion instead.