Solved

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

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

747 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

13 Experts available now in Live!

Get 1:1 Help Now