Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now