Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Sep 2001
    Location
    Stuck at work..., Missouri, USA
    Posts
    248
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Since when is '12a' a date?? (A97)

    Why does this not fail if the user enters "12a"?

    Dim strNewDate As String
    strNewDate = InputBox("What is the new Date Received for this item?", "Date Received?")
    If strNewDate = "" Or IsDate(strNewDate) = False Then
    MsgBox "You either cancelled or entered an invalid date." & vbNewLine & vbNewLine & "This item has NOT been replicated.", vbInformation, "Not Replicated"
    Exit Sub
    End If

    I even tried IsDate(CDate(strNewDate)) and it still thinks 12a is a date...
    <font face="Comic Sans MS">Morgan Erickson</font face=comic>
    morgan.erickson@sprint.com
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>-From <img src=/S/flags/Colorado.gif border=0 alt=Colorado width=30 height=18> but living in <img src=/S/flags/Missouri.gif border=0 alt=Missouri width=30 height=18>...and working in Kansas.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Since when is '12a' a date?? (A97)

    Something similar came up in the Excel forum a few days ago. Windows interprets "12a" as 12:00 AM on "day 0" (12/31/1899), and so IsDate returns True.

    Jan Karel Pieterse posted an improved function to test dates in <post#=205627>post 205627</post#>. It is for dates in dd-mm-yyyy format, but it can easily be adapted for mm/dd/yyyy format.

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Since when is '12a' a date?? (A97)

    I believe the "12a" is being interpreted as 12:00 AM, which is a valid date/time entry. It would be interpreted as 12/31/1899 12:00:00 AM as I recall - haven't tried it but something like that. You should probably add some additional validity checks to make sure the date is something reasonable, ie Not < #1/1/2000# and Not > #1/1/2004# - obviously you will need to pick the appropriate dates.
    Wendell

  4. #4
    3 Star Lounger
    Join Date
    Sep 2001
    Location
    Stuck at work..., Missouri, USA
    Posts
    248
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Since when is '12a' a date?? (A97)

    Great thanks!!

    That code worked like a champ.

    I appreciate the help!
    <font face="Comic Sans MS">Morgan Erickson</font face=comic>
    morgan.erickson@sprint.com
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>-From <img src=/S/flags/Colorado.gif border=0 alt=Colorado width=30 height=18> but living in <img src=/S/flags/Missouri.gif border=0 alt=Missouri width=30 height=18>...and working in Kansas.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •