View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Geoff Geoff is offline
external usenet poster
 
Posts: 371
Default CDate and IsDate

Hi
The following test fails using CDate, can anyone explain why and how I can
produce the correct answer 'is not valid'? As it is, CDate evaluates the
invalid year 0000 to 2000 and results in an 'out of range' result incorrectly.

Input to 3 textboxes gives:
txtDay.Text = 12
txtMonth.Text = 05
txtYear.Text = 0000

tmpdate = CDate(txtDay.Text & "/" & txtMonth.Text & "/" & txtYear.Text)
If IsDate(tmpdate) = False Then
MsgBox "Please re-enter, " & txtSDay.Text & "/" & txtSMonth.Text & "/" &
txtSYear.Text & " is not valid. ")
Exit Sub
ElseIf tmpdate < DateAdd("yyyy", -1, Now()) Or tmpdate Now() Then
MsgBox "Please re-enter, " & txtDay.Text & "/" & txtMonth.Text & "/" &
txtYear.Text & " is not within range. ")
End If

T.I.A

Geoff