The code below checks to see if there are any spaces in the Username. The problem I have is when there is text in this field with a space in it, this procedure is run and I can not close the form.
What I want to happen is when the form is being closed, it ignores this procedure altogether. I could delete the text in the field first and then close the form, or I could not allow a space to be entered in this field.Code:Private Sub txtUserName_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtUserName.LostFocus For i = 0 To txtUserName.TextLength - 1 If txtUserName.Text.Substring(i, 1) = Chr(32) Then MsgBox("Please Do Not Leave Spaces In User Name! " & vbCr & vbCr & "Please Enter Different Username. ", MsgBoxStyle.Exclamation, "New User") Exit For End If Next txtUserName.Text = "" txtUserName.Focus() End Sub
I have tried "FormClosing" without success.
Any Ideas.




Reply With Quote