Hello! I am in something of a quandary. I have been tasked with determining which reports are due each month and the date they are due. Now, some of the reports require monthly reporting, some quarterly, some annual, a few semiannual, and even at least one that is biennial. To complicate matters further, most of the monthly reports are due on the 5th business day of the month, (skipping weekends and holidays, I have a table with the holiday dates already in it) others are due on a specific date each month say the 10th. However if the 10th falls during the weekend it will be due the following Monday, so if the 10th is on Saturday the report is due on the 12th.
Just to add another layer of fun to all this, my boss wants any annual reports to begin showing up on the list 2 month prior to the due date, as calculated above. So if the report is due January 1 of each year it needs to start showing up on the list in November. I have the first occurrence and the final occurrence dates of each report, the number of calendar days or business days as required.
I have started some code that was supposed to give me the next occurrence of the reports based on the first occurrence, but all it returns is the last record, I need all of them. I was hoping I could modify this to give me each occurrence of the reports, so all I would have to do is change the first occurrence date if necessary to update the list. This code only returns the date per calendar days at the moment, I haven’t incorporated the business days, weekends and holidays, I have the code for that, but I figure the rest can be added when I get this working.
Thanks for your time, kjpreston
Public Function FindDates() As String
Dim x As String
Dim y As String
Dim z As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("DRDListing", dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF 'Or Not IsNull(rs("DRD"))
x = rs!DRD.Value & " " & rs!Title.Value
y = DateSerial(Year(rs!InitialPeriod), Month(rs!InitialPeriod) + 1, 1)
z = DateAdd("d", rs!StartDat, y)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
FindDates = x & " " & z
Debug.Print
End Function
Code for skipping weekends and holidays
Public Function SkipWendHol(sd As Date, i As Integer) As Date
Dim nd As Date
K = 0
j = 0
If Not i = 0 Then
Do While Not j = i
If i < 0 Then
j = j - 1
Else
j = j + 1
End If
nd = FormatDateTime(DateAdd("d", j, sd), vbShortDate)
If Weekday(nd, vbMonday) = 6 Or Weekday(nd, vbMonday) = 7 Then
If i < 0 Then
i = i - 1
Else
i = i + 1
End If
End If
If Not IsNull(DLookup("[HDate]", "[TTempHol]", "[HDate]=#" & nd & "#")) And Not (Weekday(nd, vbMonday) = 6 Or Weekday(nd, vbMonday) = 7) Then
If i < 0 Then
i = i - 1
Else
i = i + 1
End If
End If
Loop
SkipWendHol = nd
Else
SkipWendHol = sd
End If
End Function
Code for determining business days
Public Function busydays(b As Date, e As Date) As Integer
Dim x As Integer
Dim y As Integer
Dim w As Date
Dim h As Date
w = DateAdd("d", 2, e)
h = DateAdd("d", -1, e)
y = DateDiff("d", b, DateAdd("d", 1, e))
x = DateDiff("ww", b, e, vbSunday)
x = x + DateDiff("ww", b, e, vbSaturday)
x = x + DCount("[HDate]", "[Holiday]", "[Hdate] > #" & b & "# and [Hdate] < #" & w & "#")
busydays = y - x
End Function
Just to add another layer of fun to all this, my boss wants any annual reports to begin showing up on the list 2 month prior to the due date, as calculated above. So if the report is due January 1 of each year it needs to start showing up on the list in November. I have the first occurrence and the final occurrence dates of each report, the number of calendar days or business days as required.
I have started some code that was supposed to give me the next occurrence of the reports based on the first occurrence, but all it returns is the last record, I need all of them. I was hoping I could modify this to give me each occurrence of the reports, so all I would have to do is change the first occurrence date if necessary to update the list. This code only returns the date per calendar days at the moment, I haven’t incorporated the business days, weekends and holidays, I have the code for that, but I figure the rest can be added when I get this working.
Thanks for your time, kjpreston
Public Function FindDates() As String
Dim x As String
Dim y As String
Dim z As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("DRDListing", dbOpenDynaset)
rs.MoveFirst
Do Until rs.EOF 'Or Not IsNull(rs("DRD"))
x = rs!DRD.Value & " " & rs!Title.Value
y = DateSerial(Year(rs!InitialPeriod), Month(rs!InitialPeriod) + 1, 1)
z = DateAdd("d", rs!StartDat, y)
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
FindDates = x & " " & z
Debug.Print
End Function
Code for skipping weekends and holidays
Public Function SkipWendHol(sd As Date, i As Integer) As Date
Dim nd As Date
K = 0
j = 0
If Not i = 0 Then
Do While Not j = i
If i < 0 Then
j = j - 1
Else
j = j + 1
End If
nd = FormatDateTime(DateAdd("d", j, sd), vbShortDate)
If Weekday(nd, vbMonday) = 6 Or Weekday(nd, vbMonday) = 7 Then
If i < 0 Then
i = i - 1
Else
i = i + 1
End If
End If
If Not IsNull(DLookup("[HDate]", "[TTempHol]", "[HDate]=#" & nd & "#")) And Not (Weekday(nd, vbMonday) = 6 Or Weekday(nd, vbMonday) = 7) Then
If i < 0 Then
i = i - 1
Else
i = i + 1
End If
End If
Loop
SkipWendHol = nd
Else
SkipWendHol = sd
End If
End Function
Code for determining business days
Public Function busydays(b As Date, e As Date) As Integer
Dim x As Integer
Dim y As Integer
Dim w As Date
Dim h As Date
w = DateAdd("d", 2, e)
h = DateAdd("d", -1, e)
y = DateDiff("d", b, DateAdd("d", 1, e))
x = DateDiff("ww", b, e, vbSunday)
x = x + DateDiff("ww", b, e, vbSaturday)
x = x + DCount("[HDate]", "[Holiday]", "[Hdate] > #" & b & "# and [Hdate] < #" & w & "#")
busydays = y - x
End Function