Use the IsDate function to determine if data is a Date data type. From VB Help file:
IsDate Function
Returns a Boolean value indicating whether an expression can be converted to a date.
Syntax
IsDate(expression)
The required expression argument is a
Variant containing a date expression or string expression recognizable as a date or time.
Remarks
IsDate returns True if the expression is a date or is recognizable as a valid date; otherwise, it returns False. In Microsoft Windows, the range of valid dates is January 1, 100 A.D. through December 31, 9999 A.D.; the ranges vary among operating systems.
This code should work for you:
Sub mySub()
' Declare as variant for proper use of IsDate function
Dim myDate as Variant
' Prompt user...
myDate = InputBox("Please enter a date.")
' Check if user input is a 'Date' data type...
If Not IsDate(myDate) Then 'Type mismatch error!!!
MsgBox "You must enter a date! Please retry."
Exit Sub
End If
' Run my proceedure here
End Sub
Hope this helps,
theDude
Bookmarks