re returning multiple dates:
The function includes two optional arguments. The first is a "Date", and since I would expect that your records have dates (or date/time) field(s), supplying that field as a parameter would return the Last Weekday specified in the other optional argument, which is set to "Monday" by default (but could easily be set to any day of the week using the enumerated constants "VB" and WeekDayName (e.g. vb Wednesday). Perhaps I should have included a few "sample usage" lines to illustrate this, but I was not really concentrating when Working on this, so 'forgot'.
Here with are two (simplistic) samples for the current year, just so htey are easy to see / check:
For xx = 1 To 12: MyMnth = DateSerial(2004, xx, xx): Print xx, basLastWkDay(MyMnth): Next xx
1 1/26/04
2 2/23/04
3 3/29/04
4 4/26/04
5 5/31/04
6 6/28/04
7 7/26/04
8 8/30/04
9 9/27/04
10 10/25/04
11 11/29/04
12 12/27/04
For xx = 1 To 12: MyMnth = DateSerial(2004, xx, xx): Print xx, basLastWkDay(MyMnth, vbSaturday): Next xx
1 1/31/04
2 2/28/04
3 3/30/04
4 4/29/04
5 5/30/04
6 6/29/04
7 7/31/04
8 8/30/04
9 9/29/04
10 10/30/04
11 11/29/04
12 12/30/04
Re the SQL Statement:
While not necessarily (or even possibly) relevant:
HAVING (((tblweeklyduties.Date)=basLastWkDay()) AND ((Year([date]))=Year(Now())));
is -at best redundant.
It ?shouda, wouda, coudua? be:
HAVING (((tblweeklyduties.Date)=basLastWkDay());
First, the Year function will return the same value wit either argument, since they are just different formats of hte same value, and the difference in the format does not affect the "Year", so that clause will ALWAYS evaluate to True. Second, the instantation of the baslastWkDay function supplies no argument, so it (also) relies on the "current" date and returns a "Full" date (but without any time / fractional part), so it will restrict the return values to the specific date returned, which WILL be both in the current month and YEAR.
HOWEVER, if someone were to supply a date which were NOT in the current year to basLastWkDay, the date returned would also not be within the current year. While the current configuration (the always "true" clause) changed to some meaningful expression which (perhaps) depended on the year of the date returned from the basLastWkDay function matching hte current year, you could easily get the query to return nothing (the empty recordset.
MichaelRed
m.red@att.net
Searching for employment in all the wrong places