msgbox.okcancel result error.

Posted on 2005-04-13
Last Modified: 2012-08-13
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()
            Dim DeleteCmdBuilder As New OleDbCommandBuilder(myDataAdapter)
            Dim myDeleteRow As DataRow '= New myDataTable.Rows
            Dim i As Integer

            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
                        Exit For
                    End If
            ElseIf MsgBoxResult.Cancel Then
            End If

        Catch e As Exception
        End Try
    End Sub
Question by:scm0sml
    LVL 44

    Accepted Solution

    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

    Author Comment

    ok = 1, cancel =2 is it?

    Author Comment

    got it, cheers!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now