Thank you Steve, for your help. However, I could not get the function to work (not sure why) even after making some corrections to the variable names. Even then, I'm not sure it would have solved my problem. That being said...
I figured out the problem and fixed the DoReview function! I feel like I know something about VBA now! (Wait...that could be dangerous...)
All I did was modify the code as follows (changes are in ORANGE):
Code:
Function DoReview(ThursDate As Date, Admit_Date As Date) As Boolean
Dim SunBef As Date, SatAf As Date, SunAf As Date
Dim AdmitDay As Integer, Sun_Day As Integer, Sat_Day As Integer, Sunday_After As Integer
SunBef = DateSerial(Year(ThursDate), Month(ThursDate), Day(ThursDate) - 4) 'Date of the preceding Sunday
SatAf = DateSerial(Year(ThursDate), Month(ThursDate), Day(ThursDate) + 2) 'Date of the subsequent Saturday
SunAf = DateSerial(Year(ThursDate), Month(ThursDate), Day(ThursDate) + 3) 'Date of subsequent Sunday for days 29 thru 31
Sun_Day = Day(SunBef) 'Day of the month
Sat_Day = Day(SatAf)
Sunday_After = Day(SunAf)
AdmitDay = Day(Admit_Date)
DoReview = False
If Sun_Day < Sat_Day And Sat_Day < Sunday_After Then 'week contained in a single month
If AdmitDay >= Sun_Day And AdmitDay <= Sat_Day Then
DoReview = True
End If
ElseIf Sun_Day < Sat_Day And Sat_Day > Sunday_After Then 'Tests for months which end on Saturday and which dont contain days 29 thru 31
If AdmitDay > Sat_Day And (AdmitDay = 29 Or AdmitDay = 30 Or AdmitDay = 31) Or AdmitDay >= Sun_Day And AdmitDay <= Sat_Day Then
DoReview = True
End If
Else 'week ending on next month
If AdmitDay >= Sun_Day Or AdmitDay <= Sat_Day Then
DoReview = True
End If
End If
End Function
I also fixed an issue with the name of a couple of variables/identifiers because it was wrongly named and potentially confusing; the function correctly evaluated months ending on a Saturday, but the variable names MonAf and Monday_After were changed to SunAf and Sunday_After, respectively.
Thank you all for your help. I'll mark this thread Solved! Oh, wait...it already was... ;-)