Improve company productivity with a Business Account.Sign Up

x
?
Solved

How do I trap the X button click event

Posted on 2004-09-14
5
Medium Priority
?
270 Views
Last Modified: 2010-05-02
Hi all,

I want to ask users "Are you sure you want to exit?" when the click the X on the top right of a window.

In the form_Terminate() event I have the following code which asks the question:-

Private Sub Form_Terminate()

Dim strResponse As String

strResponse = MsgBox("Are you sure?", vbOKCancel)

If strResponse = vbOK Then
    End
Else
    ??
End If

End Sub

What can I put in the else clause to keep the form open?

Cheers,
Shivermetimbers
0
Comment
Question by:shivermetimbers
  • 2
  • 2
5 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 200 total points
ID: 12053932
Cancel=True
0
 
LVL 44

Expert Comment

by:bruintje
ID: 12053964
you could try the query unload event

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   If UnloadMode = vbFormControlMenu Then
      If MsgBox("The user used the Forms Close button" & vbCrLf & "Cancel Unload?", vbYesNo) = vbYes Then
         Cancel = True
      End If
   End If
End Sub

HTHAB
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 12053971
Private Sub Form_Unload(Cancel As Integer)
resp = MsgBox("Sure?", vbOKCancel)
If resp = vbOK Then
    Unload Me
Else
    Cancel = True
End If
End Sub
0
 
LVL 3

Expert Comment

by:aParser
ID: 12053984
Right, but Cancel = True needs to go in the Form_Unload event, not Form_Terminate.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 12054035
lol :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…

589 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