Click here to Skip to main content
16,020,378 members
Please Sign up or sign in to vote.
1.00/5 (1 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:
VB
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 1-Dec-22 17:02pm

Hope the below code example will help -

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

If(result == DialogResult.OK)
    Update data here
Else
    Nothing
End If
 
Share this answer
 
Dim ask As MsgBoxResult = MsgBox("What you Want", MsgBoxStyle.YesNo)
       If ask = MsgBoxResult.Yes Then

       End If
 
Share this answer
 
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 one... (simple one)

VB
Dim ans as string
ans= Msgbox "Confirm Update", vbYesNo
if ans= vbYes then
 'code to update
end if
 
Share this answer
 
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. :)
Dont declare variable.

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

End If
 
Share this answer
 
Comments
Richard Deeming 2-Dec-22 5:25am    
Eight years late, and you've added nothing to the discussion. Declaring a variable to store the result is not the problem!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900