Click here to Skip to main content
14,635,966 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello!
I am using Microsoft Visual Studio 2005.

How can I make a message box that can confirm action?
This is my code:
Private Sub BTNunlock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNunlock.Click
        Try
            sqlsa = "UPDATE MAS_Users set islocked='0' WHERE empno='" & TBempno.Text & "'"
            con.NoReturnQuery(sqlsa)
        Catch ex As Exception
            MsgBox("Error!", MsgBoxStyle.Critical)
        End Try
    End Sub


When I click the button, i want to show a message box that says: Confirm update? with the buttons: Yes or No

if picked yes, my data will update, if not, then no.
How can i make one?

Thanks in advance! :)
Posted
Updated 30-Jan-18 21:50pm
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hope the below code example will help -

Dim result As DialogResult = MessageBox.Show("Confirm update?", _
                              "Title", _
                              MessageBoxButtons.YesNo)

If(result == DialogResult.OK)
    Update data here
Else
    Nothing
End If
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

this one... (simple one)

Dim ans as string
ans= Msgbox "Confirm Update", vbYesNo
if ans= vbYes then
 'code to update
end if
   
Comments
F. Xaver 15-May-14 3:19am
   
y not using the newer and comfortable MessageBox.Show()
Msgbox is vb6 compatibility
Karen Mitchelle 15-May-14 3:28am
   
either way, that is, I think, okay. OP even tag VB on his/her question.

PS. I really often use MessageBox.Show(), it's just that, Msgbox is what came first in my mind. :)
Rate this:
Please Sign up or sign in to vote.

Solution 3

Dim ask As MsgBoxResult = MsgBox("What you Want", MsgBoxStyle.YesNo)
       If ask = MsgBoxResult.Yes Then

       End If
   
Comments
Richard MacCutchan 31-Jan-18 3:54am
   
Nearly FOUR years too late.
CHill60 1-Feb-18 8:56am
   
See the comments to Solution 1 - you haven't really added anything to the solutions from four years ago.
Stick to answering new posts where the OP still needs help - and be sure that your response is not just repeating earlier solutions or comments, and that it is accurate.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100