-
I would come at it from something like this:
[VBA]
Sub CalcSurveyDates(dtStartDate As Date)
Dim i As Integer
Dim dtReminderDate As Date
Dim dtAdjustedStartDate As Date
If Day(dtStartDate) < 15 Then
'The survey is in the 4th contract month
'Set the dtAdjustedStartDate to the first day of the current dtStartDate month
dtAdjustedStartDate = DateSerial(Year(dtStartDate), Month(dtStartDate), 1)
Else
'The survey is in the 5th contract month
'Set the dtAdjustedStartDate to the first day of the following dtStartDate month
dtAdjustedStartDate = DateSerial(Year(dtStartDate), Month(dtStartDate) + 1, 1)
End If
arraySurveyDates(1, 1) = AdjustWeekendDate(DateAdd(Month_IntervalType, 2, dtAdjustedStartDate))
arraySurveyDates(2, 1) = AdjustWeekendDate(DateAdd(Month_IntervalType, 3, dtAdjustedStartDate))
arraySurveyDates(3, 1) = AdjustWeekendDate(DateAdd(Day_IntervalType, 14, DateAdd(Month_IntervalType, 3, dtAdjustedStartDate)))
arraySurveyDates(4, 1) = AdjustWeekendDate(DateAdd(Month_IntervalType, 4, dtAdjustedStartDate))
arraySurveyDates(5, 1) = AdjustWeekendDate(DateAdd(Day_IntervalType, 14, DateAdd(Month_IntervalType, 4, dtAdjustedStartDate)))
arraySurveyDates(6, 1) = AdjustWeekendDate(DateAdd(Month_IntervalType, 7, dtAdjustedStartDate))
arraySurveyDates(7, 1) = AdjustWeekendDate(DateAdd(Month_IntervalType, 8, dtAdjustedStartDate))
arraySurveyDates(8, 1) = AdjustWeekendDate(DateAdd(Day_IntervalType, 14, DateAdd(Month_IntervalType, 3, dtAdjustedStartDate)))
arraySurveyDates(9, 1) = AdjustWeekendDate(DateAdd(Month_IntervalType, 9, dtAdjustedStartDate))
arraySurveyDates(10, 1) = AdjustWeekendDate(DateAdd(Day_IntervalType, 14, DateAdd(Month_IntervalType, 4, dtAdjustedStartDate)))
For i = 1 To 10
If DateDiff(Day_IntervalType, arraySurveyDates(i, 1), Date) >= MIN_REMINDER_DAYS Then
arraySurveyDates(i, 2) = STATUS_SET
Else
'Not enough time for the reminder, so set the date to null and checkbox flag to false
arraySurveyDates(i, 1) = vbNull
arraySurveyDates(i, 2) = STATUS_NOT_SET
End If
Next i
End Sub
[/VBA]
I have changed the code for the 1st of the following month, as I could not follow what you were doing with the second DateAdd statement. Also, for the 9 month reminders it looked like you were adding too many months, so I changed that as well.
TJ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules