Solved

Validate Delete Record

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

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
How to use odbc in vb to connect to ms sql 14 38
VB6 ListBox Question 4 34
Allow User To Arrange Columns At Datagridview 3 19
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

867 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

18 Experts available now in Live!

Get 1:1 Help Now