Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   VB If Statement Help (http://www.programmingforums.org/showthread.php?t=12093)

Robocop Dec 3rd, 2006 6:25 AM

VB If Statement Help
 
I just want to make these statements so that when the if is true, the message box is shown and the form is not closed. If the required fields are blank, then the form should not close, but it is closing after you click the message box. Can anybody help me with this?

Quote:

Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
If Me.edit_type.Text = "" Or Me.editname.Text = "" Then
'MessageBox.Show("Please fill the required fields.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
'Update the Dataset
Me.UpdateDataSet()
End If
End Sub

The Dark Dec 3rd, 2006 7:20 AM

A quick google for "vb onclose event" leads me to think you can just put in
that setting e.Cancel to True cancels the close.

PhilBon Dec 3rd, 2006 10:56 PM

one thing I'd suggest, not that you have to is instead of Me.edit_type.Text = "" I would use Me.edit_type.Text = nothing. To me that just seems better, don't know how others would feel. Either way works fine, I just see "Nothing" neater than ""

Robocop Dec 4th, 2006 2:40 PM

Quote:

Originally Posted by The Dark (Post 120457)
A quick google for "vb onclose event" leads me to think you can just put in
that setting e.Cancel to True cancels the close.

Thanks! it worked great!

Quote:

Originally Posted by PhilBon
one thing I'd suggest, not that you have to is instead of Me.edit_type.Text = "" I would use Me.edit_type.Text = nothing. To me that just seems better, don't know how others would feel. Either way works fine, I just see "Nothing" neater than ""

Nice idea.

BlackDal Dec 5th, 2006 4:21 PM

its better write this code into Form.Closing routine

Robocop Dec 5th, 2006 7:35 PM

Quote:

Originally Posted by BlackDal (Post 120665)
its better write this code into Form.Closing routine

That's true, "e.Cancel" didn't work with Form.Closed anyways.


All times are GMT -5. The time now is 7:38 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC