Search code examples
vb.netmessagebox

VB messagebox yes/no I want the 'no' to close message box, but its closing the form i want open


Private Sub btnMain_Click(sender As Object, e As EventArgs) Handles btnMain.Click
    Dim result As DialogResult = MessageBox.Show("Did you save customer info?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Stop)
    If (result = DialogResult.Yes) Then
        'Me.Visible = False
        Me.Close()
        frmDuneTours.Visible = True
    ElseIf (result = DialogResult.No) Then
        frmDuneTours.Visible = False
        Me.Visible = True
    End If
End Sub

Solution

  • When you place Me.Close before frmDuneTours.Visible = True the second line never executes because when you close the current form the application ends.

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Dim result As DialogResult = MessageBox.Show("Did you save customer info?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Stop)
            If (result = DialogResult.Yes) Then
                frmSortedList.Visible = True
                Me.Close()
            ElseIf (result = DialogResult.No) Then
                frmSortedList.Visible = False
            End If
    End Sub