check if date is valid

User avatar
sal21
PlatinumLounger
Posts: 3559
Joined: 26 Apr 2010, 17:36

check if date is valid

Post by sal21 »

why the code not itercept error in if not is date!!!!

in my case i need to force the user to digit correct date in this format: dd/mm/yyyy

i text box have: 15/11/980

see image!
You do not have the required permissions to view the files attached to this post.

User avatar
StuartR
Administrator
Posts: 11379
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: check if date is valid

Post by StuartR »

I guess that doesn't generate an error because it is a date, 15th November in the year 980
StuartR


User avatar
HansV
Administrator
Posts: 71177
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: check if date is valid

Post by HansV »

Use

Code: Select all

    If Not Me.TDATANASCITA.Text Like "##/##/####" Then
        ...
        Exit Sub
    End If
    If Not IsDate(Me.TDATANASCITA.Text) Then
        ...
        Exit Sub
    End If
    ...
Regards,
Hans