Here's exactly how it works! This uses a table named tblExcept. It has two
fields, ExMonth and ExYear, both are Long Integer. For this year, you need
two records, 2006 / 3 and 2006 / 9
Here is how it works. Notice we no longer need lngException. We don't even
care what the month number is. All we are concerned with is whether we find
a record in tblExcept. If there is no record that matches the month of the
date, then the DLookup returns Null, so it is not an exception. If it
returns any other value than Null, it is an exception.
Function GetStartDate(varTheDate As Date) As Date
Dim dtmStart As Date
dtmStart = DateAdd("d", 1, LastFriday(DateAdd("m", -1,
LastFriday(varTheDate))))
If Not IsNull(DLookup("[ExMonth]", "tblExcept", "[ExYear] = " _
& year(dtmStart) & " And [ExMonth] = " & Month(dtmStart))) Then
dtmStart = DateAdd("ww", -1, dtmStart)
End If
GetStartDate = dtmStart
End Function
Function GetCloseDate(varTheDate As Date) As Date
Dim dtmClose As Date
dtmClose = LastFriday(varTheDate)
If Not IsNull(DLookup("[ExMonth]", "tblExcept", "[ExYear] = " _
& year(dtmClose) & " And [ExMonth] = " & Month(dtmClose))) Then
dtmClose = DateAdd("ww", -1, dtmClose)
End If
GetCloseDate = dtmClose
End Function
Ray S. said:
That sounds exactly like what I'd like to do. How would I hook this up to the
other functions?
Klatuu said:
Glad to be of assistance, Ray. I was flattered by your original post
crediting me with assisting you with the LastFriday function.
If the months of the exceptions will change from year to year, then rather
than having to modifiy the code each year. It may make sense to create a
small two column table that you could retrieve the exception months from.
One column would be the year, and the other the exception month. So, for the
current situation, you would have 2 records 2006 / 3 and 2006 /9
To get that value you could just use a DLookup
=DLookup("[ExMonth]", "tblExcept", "[ExMonth] = " & Month(Date) _
& " And [ExYear] = " & Year(Date))
If it returns Null, then it is not an exception. If it returns a value, it is.
Best of Luck to you.
Ray S. said:
I did reply to your other question, but it's up above your reply because I
didn't wait for your reply before posting it...
Selecting 3/25/2006 as a processing date would be extremely rare if not
absolutely not a possibility. That would be the Start date of the next period
(April). The most likely scenario is that a user would select a processing
date sometime in April before the April close date. Since all the data is
kept in a database table, what I do is filter those dates to make sure that I
am processing only transactions that fall between the start and closing
dates. The effective date of the processing is the closing date of each
period. Financial periods close on the last friday of each month with a few
exceptions that are determined before the beginning of the new fiscal year.
Since they are almost always a couple of months that will close on the next
to last instead of the last friday, I want to have an easy way of making a
one-time easy selection of those exceptions. Before now we would make a new
table each year with the opening and closing dates. I know that maybe this is
a more complicated solution, but it seems more elegant to me, and I can
conceive of an easier way to make the one-time selections of the annual
exceptions. It also helps me learn more about coding. Thanks so very much for
your help. I really appreaciate it.