|
-
Aug 17th, 2005, 08:03 PM
#1
Thread Starter
Addicted Member
[RESOLVED] On Exit...
VB Code:
Private Sub frmInventory_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
Dim yesToUpdate As Integer
If changes Then
yesToUpdate = MsgBox("Changes made are not save, do you want to save the changes ?", MsgBoxStyle.DefaultButton1 + MsgBoxStyle.YesNoCancel, "Save Changes")
If yesToUpdate = vbYes Then
MsgBox("update")
ElseIf yesToUpdate = vbCancel Then
MsgBox("Close the msgbox,but not close the form")
End If
changes = False
End If
cnn.Close()
End Sub
What I want is if I click the "Cancel" button of he message box, I dont want the form to be closed. Only "Yes" and "No" will close the form.
Any idea how to achieve that?
-
Aug 17th, 2005, 08:08 PM
#2
Re: On Exit...
Your using the wrong event then. You need to use the Closing event so you can intercept the unloading and cancle it. 
VB Code:
Private Sub frmInventory_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim yesToUpdate As Integer
If changes Then
yesToUpdate = MsgBox("Changes made are not save, do you want to save the changes ?", MsgBoxStyle.DefaultButton1 + MsgBoxStyle.YesNoCancel, "Save Changes")
If yesToUpdate = vbYes Then
MsgBox("update")
ElseIf yesToUpdate = vbCancel Then
MsgBox("Close the msgbox,but not close the form")
e.Cancel = True
End If
changes = False
End If
cnn.Close()
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 17th, 2005, 10:38 PM
#3
Thread Starter
Addicted Member
-
Aug 18th, 2005, 08:31 PM
#4
Member
Re: [RESOLVED] On Exit...
Hi, i also need to implement similar function to what you have here, any idea hwo i can make this happy to my set of closing instead with a Yes and No too? Coding is as of below:
VB Code:
Private Sub Download_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Module2.sending("<logout/>")
Try
mySocket.Close()
Catch ex As Exception
MessageBox.Show("Program Terminated...")
End Try
Application.Exit()
'Me.Close()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|