Solved

Event that runs only when clicking "close" button (red "X" in upper right of window)

Posted on 2006-10-24
2
508 Views
Last Modified: 2008-02-26
Good morning,

  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()

    DoCmd.Quit

End Sub

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.

  Luke

0
Comment
Question by:potterlu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 125 total points
ID: 17796272
What you are asking about is the VB 6 Form_QueryUnload event - which has, as a parameter, the UnloadMode which can serve to indicate that the Form is being unloaded as a result of the user clicking the Close button (Red X in the upper right corner).  The forms engine used for Access is NOT the same engine as used by VB6, and thus, the events raised by the form is quite different in the two environments.  VB6 forms are not the same 'thing' as VBA forms created in Access.  

There is no Access Form event that can serve to give you the control that you are asking for.

AW
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question