Solved

Validate Delete Record

Posted on 2008-06-26
4
271 Views
Last Modified: 2013-11-26
Hello,

I'm trying to create this validation when someone clicks on the BindingNavigatorDeleteItem to give him a pope message of whether they are sure if they wanted to delete the record. If they click yes, then the delete process continues, if they press no I want to delete process to stop. but also in the event that the record gets deleted I want the applicaiton to email me with the information that was deleted.

How do I do that... my code is below... would anyone be able to assist.
Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        If MessageBox.Show("Are you sure you want to delete Note for Project" + vbCrLf + "Project Name: " & Me.ProjectNameTextBox.Text & vbCrLf & "Note added by: " & Me.NoteAddedByTextBox.Text, "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            'If no then stop the process
            Exit Sub
        Else
        	'If yes then delete the record, but send me and email message of the Project that was deleted
        	Dim lSlash As Integer = rName.LastIndexOf("\")
            Dim fName As String = rName.Substring(lSlash + 1)
            Dim emailfrm As String = fName & "@somedomainName.com"
            Dim myMailMessage As New MailMessage(emailfrm, "My email address")
            myMailMessage.Priority = MailPriority.High
            myMailMessage.Subject = "Deleted Note"
            
            Dim bodyText As String = Me.ProjectName_TextBox.text
            Dim smtpServer As New smtpClient("Server Name")
            smtpServer.Send(myMailMessage)
        End If
    End Sub

Open in new window

0
Comment
Question by:AIdoHSG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:-Thespian-
ID: 21879585
Try "Return" where "Exit Sub" is and replace "Else" with "endif" and delete last "endif"
0
 

Author Comment

by:AIdoHSG
ID: 21883173
Hello Thespian,

Thanks for the reply,
I've made the changes your suggested and still when I clicked "No" the message was deleted. I wanted to terminate the delete process.
Any thoughts.
My code is below
Private Sub BindingNavigaDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Dim dlgResult As DialogResult
        dlgResult = MessageBox.Show("Are you sure you want to delete Note for Project" + vbCrLf + "Project Name: " & Me.ProjectNameTextBox.Text & vbCrLf & "Note added by: " & Me.NoteAddedByTextBox.Text, "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If dlgResult = DialogResult.No Then
            Return
        End If
 
        'If yes then delete the record, but send me and email message of the Project that was deleted
        Dim rName As String = My.User.Name
        Dim lSlash As Integer = rName.LastIndexOf("\")
        Dim fName As String = rName.Substring(lSlash + 1)
        Dim emailfrm As String = fName & "@healthstrategies.com"
        Dim myMailMessage As New MailMessage(emailfrm, "aido@healthstrategies.com")
        myMailMessage.Priority = MailPriority.High
        myMailMessage.Subject = "Deleted Note"
 
        Dim bodyText As String = Me.ProjectNameTextBox.Text
        Dim smtpServer As New smtpClient("hsgnjex1.healthstrats.com")
        smtpServer.Send(myMailMessage)
 
    End Sub

Open in new window

0
 
LVL 5

Accepted Solution

by:
-Thespian- earned 500 total points
ID: 21883411
Set the breakpoint for line 4 and watch in debugger what is the value of dlgResult there
0
 

Author Comment

by:AIdoHSG
ID: 21883626
Hello Thespian,

I changed the property of the button to none in the binding navigator property.
and changed my code to as follows, which seems to have fixed the issue... thank you for your help with this:

Private Sub TblProjectNotesBindingNavigator_ItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles TblProjectNotesBindingNavigator.ItemClicked
        If e.ClickedItem Is Me.BindingNavigatorDeleteItem Then
            If MessageBox.Show("Are you sure you want to delete the current record?", "Confirm Delete", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.OK Then
                Dim rName As String = My.User.Name
                Dim lSlash As Integer = rName.LastIndexOf("\")
                Dim fName As String = rName.Substring(lSlash + 1)
                Dim emailfrm As String = fName & "@domain.com"
                Dim myMailMessage As New MailMessage(emailfrm, "aido@domain.com")
                myMailMessage.Priority = MailPriority.High
                myMailMessage.Subject = "Deleted Note"
                Dim bodyText As String
                Dim strProject As String = Me.ProjectNameTextBox.Text
                Dim strAddedBy As String = Me.NoteAddedByTextBox.Text
                Dim strError As String = Me.ErrorTextBox.Text
                Dim strReason As String = Me.ReasonTextBox.Text

                bodyText = "Project Name: " & strProject & vbCrLf & "Note Added By: " & strAddedBy & vbCrLf & "Note : " & strError & vbCrLf & "Details : " & strReason

                Dim HTMLContent As AlternateView = AlternateView.CreateAlternateViewFromString(bodyText)
                myMailMessage.AlternateViews.Add(HTMLContent)
                Dim smtpServer As New SmtpClient("servername.domain.com")
                smtpServer.Send(myMailMessage)

                Me.TblProjectNotesBindingNavigator.BindingSource.RemoveCurrent()

            End If
        End If
End Sub
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

739 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