Jeremy F.
Jeremy F.

Reputation: 1880

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

Upvotes: 1

Views: 27009

Answers (4)

JoshVB.NET
JoshVB.NET

Reputation: 1

Dim result = MessageBox.Show("Are you sure you want to close?", "are you sure?", MessageBoxButtons.YesNoCancel)
    If result = DialogResult.Yes Then
        Me.Close()
    End If
End Sub

Upvotes: 0

SAHID
SAHID

Reputation: 1

If MessageBox.Show("Do you want to Exit?", "EXIT MESSAGE", MessageBoxButtons.YesNo) = DialogResult.Yes Then
    Me.Close()
End If

Upvotes: 0

user2444865
user2444865

Reputation: 21

THe following is how i sovled this:

If MsgBox("Prompt", MsgBoxStyle.YesNoCancel, "Title") = MsgBoxResult.Yes Then
    ' execute command
End If

Upvotes: 2

Isuru
Isuru

Reputation: 31323

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

Upvotes: 6

Related Questions