I am doing so data validation, and need to check if a filed contains a
valid date in the format of "YYYY-MM-DD"
I would like to know if it is possible to convert this series of If's
to a Select Case. I am having trouble incorporating the various
functions (len(), isdate(). The IF's work, but I know this could be
better and more flexible. Any suggestions would be greatly appreciated.
:
'--------------------------------
If Len(str_CheckDate) <> 10 Then
'null check, field must contain something
fun_CheckDateFormat = False
ElseIf str_CheckDate = "" Then
'null check, field must contain something
fun_CheckDateFormat = False
ElseIf IsDate(str_CheckDate) Then
'Check if a valid date
' - If invalid format, need to indicate a 'formatting' error of
some kind
'must contain '-' as seperator character
If Mid(str_CheckDate, 5, 1) <> "-" Or _
Mid(str_CheckDate, 8, 1) <> "-" Then
fun_CheckDateFormat = False
Else
str_Year = Left(str_CheckDate, 4)
str_Month = Mid(str_CheckDate, 6, 2)
str_Day = Right(str_CheckDate, 2)
'check for valid year
If str_Year <= Year(Now()) - 25 Then
fun_CheckDateFormat = False
End If
'check for valid month
If str_Month < 1 Or str_Month > 12 Then
fun_CheckDateFormat = False
End If
'check for valid day in month
If Not (str_Day > 0 And str_Day <= Day(DateSerial(str_Year,
str_Month + 1, 0))) Then
fun_CheckDateFormat = False
End If
End If
ElseIf Not IsDate(str_CheckDate) Then
fun_CheckDateFormat = False
End If
'--------------------------------
Basically, can you do a CASE with the functions? How?:
Select Case str_CheckDate
Case Len() <> 10 ...
....
End Select