Date validation

  • Thread starter Thread starter ChrisK
  • Start date Start date
C

ChrisK

Can anyone help with a small date validation problem which my son is
struggling with as part of a school exam project.
He needs to validate a date entered but ensure it is between 1st November
and 23rd December irrespective of year. The methods he has already tried
automatically put in the current year of 2005 but he wants it so that the
year does not matter as long as it is between the specified dates.

Hope you can understand this and that someone can help.

Chris K
 
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim iDay as Integer
Dim iMonth As Integer

If Not IsNull(Me.MyDate) Then
iDay = Day(Me.MyDate)
iMonth = Month(Me.MyDate)
If (iMonth = 12 And iDay > 23) Or (iMonth < 11) Then
Cancel = True
MsgBox "Date out of range."
End If
End If
End Sub
 
Chris,
Since it's an exam item, your son should work out the solution, or see
his instructor.

He'll need to use the Month Function and the Day Function of an entered
date (ex. [TestDate]).

If TestDate = 9/14/2005 then...
Month(TestDate) would equal 9
Day(TestDate) would equal 14.

Hint: If any TestDate has a Month of 11 then it's OK.
hth
Al Camp
 
Back
Top