Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27357

Clear textbox and SetFocus for valid date entry

$
0
0
Hi

Here's what I need to accomplish:

If the entry is a valid date the program should notify the user that the date is valid, clear the textbox and set the focus to the textbox ready for a new date

I am able to do this for NOT a valid date, but when the date is a valid date the textbox does not clear and I do not get the focus. I guess I'm missing something after " Else End if" to get this to work. Any help is appreciated. Thanks.

My work is as follows:

Private Sub CheckDate_Validating(sender As Object, e As EventArgs) Handles CheckDate.MouseClick
Dim dt As String = DateTime.Now
Dim ResponseDialogResult As DialogResult
Format(dt, "MM/dd/yyyy")


' Configure the message box to be displayed
Dim messageBox1Text As String = "is Not a valid date"
Dim messageBox2Text As String = "IS a valid date"
If Date.TryParseExact(txtDoj.Text.ToString(), "MM/dd/yyyy", System.Globalization.CultureInfo.CurrentCulture, Globalization.DateTimeStyles.None, dt) Then
' Display message box
ResponseDialogResult = MessageBox.Show(messageBox2Text)
txtDoj.Clear()
txtDoj.Focus()
Else
End If

' Display message box
ResponseDialogResult = MessageBox.Show(messageBox1Text)
txtDoj.Clear()
txtDoj.Focus()

Viewing all articles
Browse latest Browse all 27357

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>