IsDate

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

Strange, that when I use IsDate to check for
a valid date entered in a form, that 14/1/99
returns True. While it's true that 14/1/99 can
be converted to February 1, 2000 I would
be more than suspect that other uses of the
entered date would cause un-desirable
consequences elsewhere.

Bill
 
Bill said:
Strange, that when I use IsDate to check for
a valid date entered in a form, that 14/1/99
returns True. While it's true that 14/1/99 can
be converted to February 1, 2000 I would
be more than suspect that other uses of the
entered date would cause un-desirable
consequences elsewhere.


Actually, Access converts 14/1/99 to Jan 14, 1999 (use CDate
to see it). It can be aggrevating when Access goes so far
out of its way to make a date out of all kinds of odd
things. Can you guess what dates 1/2, 14/2 and 33/2 are?
(BTW, you can get similarly confusing results using
IsNumeric if you are not thinking about the entire set of
possibilities.)

OTOH, if you are using DateSerial to get Feb 1, 2000, it's
your own fault for failing to check to make sure the first
number is an acceptable (to you) month number.
 
Marshall Barton said:
Actually, Access converts 14/1/99 to Jan 14, 1999 (use CDate
to see it). It can be aggrevating when Access goes so far
out of its way to make a date out of all kinds of odd
things. Can you guess what dates 1/2, 14/2 and 33/2 are?
(BTW, you can get similarly confusing results using
IsNumeric if you are not thinking about the entire set of
possibilities.)

OTOH, if you are using DateSerial to get Feb 1, 2000, it's
your own fault for failing to check to make sure the first
number is an acceptable (to you) month number.

What I actually code to check user's input for mm/dd is
something like:

Private Sub tbBeg_Before_Update(............
Dim Ar() as Integer
Ar = Split(Me.tbBeg, "/")
If Ubound(Ar) <> 2 Then 'Options 1 in effect
Msgbox Me.tbBeg & " is not a valid expression of mm/dd....blah blah
Cancel = True
Me.tbBeg.undo
Else
If Ar(1) >= 1 AND Ar(1) <= 12 then
blah
blah
blah
End Sub

Bill
Else
 
Bill said:
What I actually code to check user's input for mm/dd is
something like:

Private Sub tbBeg_Before_Update(............
Dim Ar() as Integer
Ar = Split(Me.tbBeg, "/")
If Ubound(Ar) <> 2 Then 'Options 1 in effect
Msgbox Me.tbBeg & " is not a valid expression of mm/dd....blah blah
Cancel = True
Me.tbBeg.undo
Else
If Ar(1) >= 1 AND Ar(1) <= 12 then
blah
blah


Looks like a valid approach.

As long as it's not in a heads down data entry situation, I
just let the user enter dates however they want and let the
display show how it was interpreted.
 
Access is used all over the world. The majority of countries use mm/dd/yy
or mm/dd/yyyy rather than the dd/mm/yyyy that we commonly use in the United
States, so interpreting 14/1/99 as a valid date isn't unusual. Forcing date
entry is one of the few times I can remember using the Edit Mask in
Access... when we were doing Y2K remediation. But, you can do it in a more
user-friendly fashion, in code, as you are describing.

Larry Linson
Microsoft Office Access MVP
 
Back
Top