?
Solved

Stopping a Query Unload

Posted on 2003-02-28
5
Medium Priority
?
337 Views
Last Modified: 2010-04-07
Is there a way to stop a query unload?  We disabled the X's in our program, but the users wanted them back.  Now, we call the "cancel" button on query unload, and it asks if they want to cancel, but due to the query unload, it closes even if they say no.   Thanks in advance!
  -Al
0
Comment
Question by:afeld
5 Comments
 
LVL 1

Accepted Solution

by:
alex_chiranand earned 200 total points
ID: 8044011
From MSDN help:

Private Sub Form_QueryUnload(cancel As Integer, unloadmode As Integer)

And the cancel argument:
cancel - An integer.

Setting this argument to any value other than 0 stops the QueryUnload event in all loaded forms and stops the form and application from closing.
0
 
LVL 1

Expert Comment

by:alex_chiranand
ID: 8044026
From MSDN help:

Private Sub Form_QueryUnload(cancel As Integer, unloadmode As Integer)

And the cancel argument:
cancel - An integer.

Setting this argument to any value other than 0 stops the QueryUnload event in all loaded forms and stops the form and application from closing.
0
 

Author Comment

by:afeld
ID: 8044034
Excellent!  Thanks!
0
 
LVL 2

Expert Comment

by:Jacamar
ID: 8044039
If MsgBox("Are You Sure You Want To Close Program?", vbQuestion + vbYesNo + vbDefaultButton2, "Exit Program?") = vbYes Then
    Unload Me
End If

This is the code that you can put in the cancel button.
0
 
LVL 5

Expert Comment

by:bob_online
ID: 8044056
The problem with that solution is then you can never exit the form.

Make a module level variable like mOKtoUnload As Boolean

In the QueryUnload event do

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

   If Not mOKToUnload Then
      cmdClose_Click
   End If

   Cancel = Not mOKtoUnload

End Sub

In your command button procedure set mOKToUnload to true if they answer yes, and to false if they answer no.  Now clicking the X will cause the close button code to execute and if they answer no, cancel the unload.  If they use the close button, which presumeably executes unload me or something like that, the QueryUnload event is still going to fire, but now mOktoUnload will already be True and it will not call the close button code and will only set Cancel to false.


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

621 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