Not clear whether the close button is a button you've created, or if it is
the X on the form.
If it's a button, then use its click event.
If it's the X, then look at the terminate and deactivate events for the
form. I think it's the terminate event you want, but put code in for both.