Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-10-24
2
Medium Priority
?
535 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 500 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)

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

688 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