[edit - delete. that was bad. stay tuned.]
The following query will try to find records's in a table called holidays that fall within the same week as an input date called [InputDate]
Code:
PARAMETERS InputDate DateTime;
SELECT Holidays.Holiday, Holidays.HolidayDate
FROM Holidays
WHERE (((Holidays.HolidayDate)>=[InputDate]-Weekday([InputDate])+2) AND ((Holidays.HolidayDate)<[InputDate]-Weekday([InputDate])+7));
Here's how you might use it in a generic function:
Code:
Public Function FindHolidayWeek(InputDate As Date) As Variant
On Error GoTo ErrHandler
Dim rs As DAO.Recordset
Dim mon As Date
Dim qry As String
mon = InputDate - Weekday(InputDate) + 2
qry = "SELECT Holidays.HolidayDate" & _
" FROM Holidays" & _
" WHERE Holidays.HolidayDate>=#" & mon & "# AND Holidays.HolidayDate<#" & (mon + 5) & "#;"
Set rs = CurrentDb.OpenRecordset(qry)
If Not (rs.BOF And rs.EOF) Then
FindHolidayWeek = rs!HolidayDate
Else
FindHolidayWeek = Null
End If
rs.Close
ExitHandler:
Set rs = Nothing
Exit Function
ErrHandler:
MsgBox "Error"
FindHolidayWeek = Err
Resume ExitHandler
End Function
And you could call it from a textbox's BeforeUpdate event like so:
Code:
Private Sub txtInputDate_BeforeUpdate(Cancel As Integer)
Dim holiday As Variant
holiday = FindHolidayWeek(Me.txtInputDate)
If Not IsNull(holiday) Then
MsgBox "The input date is in the same week as a holiday on " & holiday & "."
End If
End Sub