Solved

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

Posted on 2006-10-24
2
473 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

828 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