Results 1 to 4 of 4

Thread: [RESOLVED] On Exit...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Resolved [RESOLVED] On Exit...

    VB Code:
    1. Private Sub frmInventory_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
    2.         Dim yesToUpdate As Integer
    3.  
    4.         If changes Then
    5.             yesToUpdate = MsgBox("Changes made are not save, do you want to save the changes ?", MsgBoxStyle.DefaultButton1 + MsgBoxStyle.YesNoCancel, "Save Changes")
    6.             If yesToUpdate = vbYes Then
    7.                 MsgBox("update")
    8.             ElseIf yesToUpdate = vbCancel Then
    9.                 MsgBox("Close the msgbox,but not close the form")
    10.             End If
    11.  
    12.             changes = False
    13.         End If
    14.         cnn.Close()
    15.     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?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. Private Sub frmInventory_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.     Dim yesToUpdate As Integer
    3.    
    4.     If changes Then
    5.             yesToUpdate = MsgBox("Changes made are not save, do you want to save the changes ?", MsgBoxStyle.DefaultButton1 + MsgBoxStyle.YesNoCancel, "Save Changes")
    6.             If yesToUpdate = vbYes Then
    7.                 MsgBox("update")
    8.             ElseIf yesToUpdate = vbCancel Then
    9.                 MsgBox("Close the msgbox,but not close the form")
    10.                 e.Cancel = True
    11.             End If
    12.             changes = False
    13.         End If
    14.         cnn.Close()
    15. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Re: On Exit...

    Wow...It works..

    Thanks.

  4. #4
    Member
    Join Date
    Jun 2005
    Posts
    37

    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:
    1. Private Sub Download_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.         Module2.sending("<logout/>")
    3.         Try
    4.             mySocket.Close()
    5.         Catch ex As Exception
    6.             MessageBox.Show("Program Terminated...")
    7.         End Try
    8.         Application.Exit()
    9.         'Me.Close()
    10.     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
  •  



Click Here to Expand Forum to Full Width