ISDATE Code

R

Red

Happy new year to all!!

The below code is meant to highlight if the data entered isn't a date and
prompts user to renter, however when tested by entering normal text I get a
Data Mismatch error. I'd really appreciate help on changing the code to
prevent this error.

Thanks in advance.

Private Function myStart() As Date

'define start date and finish date = start date + 18 weeks)
myStart = InputBox("Enter Report Start Date (DD/MM/YY)", "Availability
Start")

If IsDate(myStart) = False Then
MsgBox "Please re-enter the start date using the format dd/mm/yy",
vbOKOnly, "Report Date Error"
myStart = InputBox("Enter Report Start Date (mm/dd/yy)", "Availability
Start")

If IsDate(myStart) = False Then
MsgBox "Error in entering reporting start date", vbCritical, "Date
Error"
End
End If

End If

End Function
 
W

WMD

Here is your code with an adjustment to the first if statement...I think this is what you are trying to get.... your original code failed at the point of data collection and thus did not evaluate the way you intended.

Private Function myStart() As Dat
On Error Resume Nex
'define start date and finish date = start date + 18 weeks
'myStart = InputBox("Enter Report Start Date (DD/MM/YY)", "Availability Start "

If IsDate(myStart = InputBox("Enter Report Start Date (DD/MM/YY)", "Availability Start ")) The
MsgBox "Please re-enter the start date using the format dd/mm/yy", vbOKOnly, "Report Date Error
myStart = InputBox("Enter Report Start Date (mm/dd/yy)", "Availability Start "

If Not IsDate(myStart) The
MsgBox "Error in entering reporting start date", vbCritical, "Date
Error "
En
End I

End I

End Function
 
R

Rod Gill

Hi,

I use:
myDate=cdate(inputbox("Enetr Date"))
if mydate=0 then
msgbox "Bad date"
else
msgbox mydate
end if

Rod Gill
www.projectlearning.com
WMD said:
Here is your code with an adjustment to the first if statement...I think
this is what you are trying to get.... your original code failed at the
point of data collection and thus did not evaluate the way you intended..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top