You're actually doing two distinct things. First, you need to check that the
user has entered a real date. You should not be forcing the user to adopt
the US (or any) date convention; you should respect their regional settings.
None of the date conversion functions like CDate() or DateValue() is
bulletproof, but they work reasonably well for most purposes most of the
time. Convert the user string to a date variable, and deal with any error
that arises if the string is invalid. (If you need bulletproof, use a
DatePicker or similar control that is guaranteed to return a date.)
Then make your comparison. Since dates are actually numbers, simple
comparison works fine.
"AndyG" wrote in message
> Could someone please tell me how to do a date comparison. I have
> txtCheckDate (a text box), and cmdCheckDate (a command button). I would
like
> the user to enter a date in mm/dd/ccyy format, and then I would like to
see
> if the date entered is either => the current system date
>
> something like
>
> if txtCheckDate < Now then
> msgbox "Date entered is in the past", , "Check Date"
> end if
>
> I get all sorts of errors, perhaps the data types are wrong. I can get it
to
> work by loading variables with mm, dd, ccyy for both current date (byte
> addressing the Now), and also the entered check date, multiplying them by
1
> and using them as integers. However that is bad coding. There must be a
> simple way to do this. Please help
>
> Thanks in advance
> God bless you
>
> >> Stay informed about: Date comparison