vb.netinfopath

Yes/No function in a messagebox


I want to add a yes/no function to a message box (Are you sure you want to exit?) in InfoPath 2007. If the user clicks 'Yes' the InfoPath form closes, if no, then the user is taken back to the form. From what I have read this will not happen in InfoPath. So, I added a new windows form that has the Yes/No buttons.

For the 'No' button, I have (me.close) which closes the windows form and the user is left with the InfoPath form. I need help when the user clicks 'Yes' meaning they want to close the windows form AND the InfoPath form. Below is my code so far. Many thanks in advance.

Imports Microsoft.Office.InfoPath 
Imports System 
Imports System.Xml 
Imports System.Xml.XPath 
Imports System.Diagnostics

Public Class Confirm_Close 
Private Sub btnNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNo.Click 

Me.Close() 

End Sub 

Private Sub btnYes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYes.Click 

Try 

<need help here>

Catch ex As Exception 

Console.WriteLine(ex.Message) 

End Try 

End Sub 

End Class

Solution

  • Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    
        If MessageBox.Show("Do you want to exit?", "Title", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
    
            Me.Close()
    
        End If
    
    End Sub