?
Solved

Stopping a Query Unload

Posted on 2003-02-28
5
Medium Priority
?
329 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
[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
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

764 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