Close InfoPath form with VB Yes/No window RRS feed

  • Question

  • 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 Catch ex As Exception Console.WriteLine(ex.Message) End Try End Sub End Class

    Tuesday, February 7, 2012 5:41 PM


  • Hi Sid244,

    Thanks for posting in MSDN Forum.

    According to your description, I provide your following snippet to see whether it fit your goal.

    Public Class ThisAddIn
        Private Sub ThisAddIn_Startup() Handles Me.Startup
            Dim r As MsgBoxResult
            r = MsgBox("Close InfoPath?", MsgBoxStyle.YesNo, "Alert")
            If r = MsgBoxResult.Yes Then
            End If
        End Sub
        Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
        End Sub
    End Class

    Have a good day,


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, February 10, 2012 3:34 AM