?
Solved

Exiting closing function

Posted on 2006-04-07
3
Medium Priority
?
138 Views
Last Modified: 2010-04-23
I need to validate a form.  When I do it at closing, it will not let me exit sub and not close, the form just continues to close.  Where can I put the validation.  Thank you


Private Sub frmrecordsmanagment_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        'update tblrecordmanagment with lngpatientid, boxnum, datearchive, description, date to be destoryed



        Dim deptnumber, todaysdate
        Dim full
        deptnumber = 1
        todaysdate = Now
        If CheckBox1.Checked = True Then
            full = 1
        Else
            full = 0
        End If

        If cancelrm = 0 Then

            'check to see if box is full

            Dim boxnumber
            If TextBox2.Text <> "" Then
                Dim cmdins As New SqlClient.SqlCommand("Select ysnboxfull from tblrecordsmanagment where boxnum = '" & TextBox2.Text & "' and ysnboxfull = 1", Connection1)
                Try
                    boxnumber = cmdins.ExecuteScalar.ToString

                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            Else
                MsgBox("Cannot exit without entering box numnber.  Please Enter Box Number!")
                Exit Sub
            End If

            If boxnumber = True Then
                Dim ans As Int32
                ans = MsgBox("You have checked that this box is full on a prior record. Do you wish to add this record to this box number?, If so please click Yes!", MsgBoxStyle.YesNo)

                If ans = 6 Then

                Else
                    MsgBox("Please assign New Box Number!", MsgBoxStyle.OKCancel)
                    Exit Sub
                End If
            End If


 
0
Comment
Question by:running32
  • 2
3 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 16400763
Hi running32,

e.cancel=True

Whereever you need to stop the closing from happening.

Tim Cottee
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 total points
ID: 16400770
running32,

For example:

            Dim boxnumber
            If TextBox2.Text <> "" Then
                Dim cmdins As New SqlClient.SqlCommand("Select ysnboxfull from tblrecordsmanagment where boxnum = '" & TextBox2.Text & "' and ysnboxfull = 1", Connection1)
                Try
                    boxnumber = cmdins.ExecuteScalar.ToString

                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            Else
                MsgBox("Cannot exit without entering box numnber.  Please Enter Box Number!")
                    e.Cancel = True
                Exit Sub
            End If

            If boxnumber = True Then
                Dim ans As Int32
                ans = MsgBox("You have checked that this box is full on a prior record. Do you wish to add this record to this box number?, If so please click Yes!", MsgBoxStyle.YesNo)

                If ans = 6 Then

                Else
                    MsgBox("Please assign New Box Number!", MsgBoxStyle.OKCancel)
                    e.Cancel = True
                    Exit Sub
                End If
            End If

Tim
0
 

Author Comment

by:running32
ID: 16401673
I forgot to say it was part of a tab. So it needs to pick up the tab name otherwise it continues to close.  Sorry
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

807 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