Event that runs only when clicking "close" button (red "X" in upper right of window)
Posted on 2006-10-24
I am currently writing a program using VBA (essentially a front end for an Access database). I was wondering if there are any events that run only when clicking a "close" button (the red "X" in the upper right hand corner of the form)?
At the moment, I have a button on my form called "cmdExit" that allows the user to completely exit the database. When the user clicks this button, the following code runs:
Private Sub cmdExit_Click()
I would like to have the same code run when I press the "X" button.
I have tried running this code on form unload and close, but obviously, these fire each time I navigate to a new form, not just when I press the "X" button. Any help would be much appreciated. Thank you for your time.