• Since when is ’12a’ a date?? (A97)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Since when is ’12a’ a date?? (A97)

    Author
    Topic
    #380915

    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…

    Viewing 1 reply thread
    Author
    Replies
    • #639830

      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. It is for dates in dd-mm-yyyy format, but it can easily be adapted for mm/dd/yyyy format.

      • #639845

        Great thanks!!

        That code worked like a champ.

        I appreciate the help!

    • #639831

      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/2004# – obviously you will need to pick the appropriate dates.

    Viewing 1 reply thread
    Reply To: Since when is ’12a’ a date?? (A97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: