Solved

Validate Delete Record

Posted on 2008-06-26
4
258 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
  • 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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