• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

msgbox.okcancel result error.

Ive got this procedure to delete a row from a datatable. I'm asking the user to confirm the action using the msgbox but what ever the user clicks the msgboxresult.ok code is being run, even if cancel is being clicked......
Any1 help?

Private Sub DeleteTitle()
        Try
            Dim DeleteCmdBuilder As New OleDbCommandBuilder(myDataAdapter)
            Dim myDeleteRow As DataRow '= New myDataTable.Rows
            Dim i As Integer
            'myDataAdapter.Fill(myDataTable)

            MsgBox("You Are About To Delete Job Title '" & cmbSrcTitle.Text & "'..Do You Want To Continue?", _
        MsgBoxStyle.OKCancel, "Job Title Deletion")

            If MsgBoxResult.OK Then   ' User chose Yes.
                For Each myDeleteRow In myDataTable.Rows
                    If myDeleteRow("strJobTypeTAG") = cmbSrcTitle.Text Then
                        myDeleteRow.Delete()
                        myDataAdapter.Update(myDataTable)
                        myDataTable.AcceptChanges()
                        NewPageFormat()
                        Exit For
                    End If
                Next
            ElseIf MsgBoxResult.Cancel Then
                myDataTable.RejectChanges()
            End If

        Catch e As Exception
            MsgBox(e.ToString)
            End
        End Try
    End Sub
0
scm0sml
Asked:
scm0sml
  • 2
1 Solution
 
TimCotteeCommented:
Hi scm0sml,

            Dim Result As Integer = MsgBox("You Are About To Delete Job Title '" & cmbSrcTitle.Text & "'..Do You Want To Continue?", _
        MsgBoxStyle.OKCancel, "Job Title Deletion")

            If Result = MsgBoxResult.OK Then   ' User chose Yes.

MsgboxResult.OK is a value and not the result of the msgbox, you need to assign the returned value from the msgbox call to a variable and then test the variable.

Tim Cottee
0
 
scm0smlAuthor Commented:
ok = 1, cancel =2 is it?
0
 
scm0smlAuthor Commented:
got it, cheers!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now