Thread: is date?
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default is date?

Maybe you can check the year to see if it's valid for your data:

Dim datStartDate As Date
datStartDate = Application.InputBox(Prompt:="Enter a date", Type:=1)
If Year(datStartDate) < 2005 _
Or Year(datStartDate) 2010 Then
MsgBox "Please enter a valid date"
Else
MsgBox Format(datStartDate, "mmmm dd, yyyy")
End If

Application.inputbox with type:=1 won't let the user enter 2007-04-35.



Arne Hegefors wrote:

Hi Nick! Yes to me it seems like isDate only gives false when the actual
format is no good. when the date is nonsens but format is godd eg 2007-04-35
vba reads it like 00:00:00. si it fixed it lik this:

If IsDate(datStartdate) = True Then
If datStartdate = "00:00:00" Then
MsgBox "Invalid start date. Please enter valid start date.",
vbOKOnly, "Error message"
Exit Sub
End If
End If

"NickHK" skrev:

Arne,
In the immediate window:
?isdate("2007-04-33")
False

You mean this returns true for you ?

NickHK

"Arne Hegefors" wrote in message
...
Hi! i want to check if dates that i use as input into a program are valid
dates ie they exist. Now i have a rudimenatry control using the isDate
function in vba. however that does not do it if i write an invalid date
usijng the correct date format eg 2007-04-33. is there any way to check to
see if a date is ok or not? i would really appreciate help regarding this
matter. thanks alot!





--

Dave Peterson