Date Validation?

  • Thread starter Thread starter R-Enemy
  • Start date Start date
R

R-Enemy

I have a text box for dates. How do I validate whether it
is a date or not? I have tried the isDate() function and
it seems to return false sometimes and true other times. I
want to use either mm/dd/yy or mm/dd/yyyy format, it
doesn't matter. If anyone has used TaxCut, their textboxes
automatically places the "/" while typing and wont let you
put anything in other than a valid number, this forces the
correct mm/dd/yyyy format. Is this possible with VB.

Thanks for any help.
 
Hi

This is working for me

I will not leave the textbox until you fill in a date

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsDate(TextBox1) = False Then
Cancel = True
MsgBox "Not a valid date."
Else
MsgBox "Valid date"
End If
End Sub
 
Thanks, I'll try that. I think my problem might be that I
set a variable to the textbox.text and then did the isDate
function. Like this:

Dim a as String
if isDate(a) = false then
call msgbox("invalid date")
textbox1.setFocus
End if

I like the not being able to exit until valid. Thanks.

-----Original Message-----
Hi

This is working for me

I will not leave the textbox until you fill in a date

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsDate(TextBox1) = False Then
Cancel = True
MsgBox "Not a valid date."
Else
MsgBox "Valid date"
End If
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)




"R-Enemy" <[email protected]> wrote in
message news:[email protected]...
 
Back
Top