Solved

Validate Delete Record

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

832 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