Sunday, March 14, 2010

Validate Date in VBA

Sub Feed_Check_Date_Function()

‘ Date is within the Valid Range
Check_Date “2011-09-01?, “2011-09-10?, “2011-09-01?

‘ Date is NOT within the Valid Range
Check_Date “2011-09-01?, “2011-09-10?, “2011-09-21?

End Sub

Function Check_Date(ByVal StartDate As Date, ByVal EndDate As Date, ByVal DateTobeChecked As Date)

If DateDiff(“d”, StartDate, DateTobeChecked) <> 0 Then
MsgBox “Enter a correct date!!!!!”
End If

End Function

No comments: