Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
        Dim subName As String = txtName.Text
        Dim subadd As String = txtAdd.Text
        Dim subage As String = txtAge.Text
        Dim subsex As String = txtSex.Text
        Dim subOcc As String = txtOcc.Text
        Dim subCS As String = txtCS.Text
        Dim subcn As String = txtCN.Text
        Dim subremarks As String = txtRemarks.Text

        MsgBox("Delete Record?", MsgBoxStyle.YesNo)
        If MsgBoxResult.Yes Then
            provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
            dataFile = "C:\Dr Logger\Dr Logger Files1.accdb"
            connString = provider & dataFile
            myConnection.ConnectionString = connString
            myConnection.Open()
            Dim str As String
            str = "Delete from Logs Where Name = '" & txtName.Text & "'"
            Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
            Try
                cmd.ExecuteNonQuery()
                cmd.Dispose()
                myConnection.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            ListBox1.Items.Remove(ListBox1.SelectedItem)

            txtName.Text = ""
            txtAdd.Text = ""
            txtAge.Text = ""
            txtSex.Text = "-----"
            txtCN.Text = ""
            txtCS.Text = "-----"
            txtRemarks.Text = ""
            txtOcc.Text = ""
        ElseIf MsgBoxResult.No Then
            txtName.Text = subName
            txtAdd.Text = subadd
            txtAge.Text = subage
            txtSex.Text = subsex
            txtCN.Text = subcn
            txtCS.Text = subCS
            txtRemarks.Text = subremarks
            txtOcc.Text = subOcc
        End If


    End Sub
Posted
Comments
OriginalGriff 14-Jul-15 6:45am    
"Does no do what's it's supposed to do" doesn't help anyone: only you have any idea what you expected it to do - we have no idea what you meant it to do, although we have a reasonable idea what it is going to actually do.

Use the "Improve question" widget to edit your question and provide better information.

You're probably referring to these lines
VB
MsgBox("Delete Record?", MsgBoxStyle.YesNo)
If MsgBoxResult.Yes Then

The problem is that you don't store the result of the messagebox
Try for example like this
VB
If MsgBoxResult.Yes = MsgBox("Delete Record?", MsgBoxStyle.YesNo)Then

or if you want to use a variable then perhaps

VB
Dim result
result = MsgBox("Delete Record?", MsgBoxStyle.YesNo)
If MsgBoxResult.Yes Then
 
Share this answer
 
v2
MsgBoxResult is an enum not the results of the answer from the end user...
Catch the answer than compare it to the enum...
VB
Dim result = MsgBox("Delete Record?", MsgBoxStyle.YesNo)
If result = MsgBoxResult.Yes
...
 
Share this answer
 

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