I'm also trying to error check for Letters using the following code:
If IsNumeric(DOB.Text) = False Then
MsgBox("Please use correct format")
End If
However it doesn't accept / and if a letter has been entered it stays in the box and i have to manually erase it, would there be a way for vb to stop it going in altogether with the error msg still being displayed?
Main Topics
Browse All Topics





by: HooKooDooKuPosted on 2008-10-25 at 21:28:35ID: 22806100
You can not pass a string to "Convert.ToDateTime" that is not a valid date.
There are two tools that are available to you:
The first is that VB has a control MaskedTextBox where you can set a mask that looks like a date.
The second is a function "IsDate" that will let you know if a string can be interpreted as a date.
What you need to do is once the user has keyed in the full date, use IsDate to test if the string is a valid date, and if it is not, popup a message box telling them the field does not have a valid date in it and set focus back to the date field. Only AFTER the string has passed the IsDate test should you use Convert.ToDateTime to convert the input string to a date value.