That's because your newsreader has split the line over two. It should all be
a single line. This is something you need to watch out form when code is
posted here.
However, you must include the starting day of the working week, which in your
case is a Monday, so the value to be passed into the function is 2:
Week: WeekStart(2,[CompletedandReturnedDate])
The second argument is optional if you want to return the start date for the
week of the current date, but in your case it's the starting date of the week
for the CompletedandReturnedDate so you need both arguments.
I notice that some of the code is repeated in your last post?? The function
should be pasted into a module exactly as I posted it, and the spurious line
break in the first line removed:
Public Function WeekStart(intStartDay As Integer, Optional varDate As Variant)
As Variant
' Returns 'week starting' date for any date
' Arguments:
' 1. intStartDay - weekday on which week starts, 1-7 (Sun - Sat)
' 2. vardate - optional date value for which week starting
' date to be returned. Defaults to current date
If IsMissing(varDate) Then varDate = VBA.Date
If Not IsNull(varDate) Then
WeekStart = varDate - Weekday(varDate, intStartDay) + 1
End If
End Function
Ken Sheridan
Stafford, England
Alaska1 wrote:
I have used the code you provided in the module calling it Function.
I am getting an error on the second line As Variant
Public Function WeekStart(intStartDay As Integer, Optional varDate As Variant)
As Variant
' Returns 'week starting' date for any date
' Arguments:
' 1. intStartDay - weekday on which week starts, 1-7 (Sun - Sat)
' 2. vardate - optional date value for which week starting
' date to be returned. Defaults to current date
If IsMissing(varDate) Then varDate = VBA.Date
If Not IsNull(varDate) Then
WeekStart = varDate - Weekday(varDate, intStartDay) + 1
End If
Public Function WeekStart(intStartDay As Integer, Optional varDate As Variant)
As Variant
' Returns 'week starting' date for any date
' Arguments:
' 1. intStartDay - weekday on which week starts, 1-7 (Sun - Sat)
' 2. vardate - optional date value for which week starting
' date to be returned. Defaults to current date
If IsMissing(varDate) Then varDate = VBA.Date
If Not IsNull(varDate) Then
WeekStart = varDate - Weekday(varDate, intStartDay) + 1
End If
I have added it into the query as a column
Week: WeekStart([CompletedandReturnedDate])
with CompletedandReturnedDate having the date in that field. WeekStart is
my public function name. I am getting an error in the query. It is not
pulling any data for that field.
Best to do it in the query as a computed column in the way I described in my
last post. Then you can group on the column and include a text box in the
[quoted text clipped - 25 lines]
5/24/2010 - 5/28/2010 5 time sheets returned
.
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/201005/1