Hi Derek,
First let me correct my last post:
If I wanted to know the Sunday
and Saturday dates of *current week*,
I'd use:
Date()-(Weekday(Date())-1) AS SundayOfWeek
Date()-(Weekday(Date())-7) AS SaturdayOfWeek
If your field "AppointmentDate" contained time values, your Where clause
might look like:
WHERE
[AppointmentDate] >= Date()-(Weekday(Date())-1)
AND
[AppointmentDate]< Date()-(Weekday(Date())-7) + 1
Sorry, I meant to go back and correct that but forgot....
Next, let me ask, if you don't mind, if "week numbers"
are the only way your users can relate to requesting a
weekly report on your form?
And, will they only be requesting for the current year
or future years, i.e., never for past years?
This might be one way:
Create a "tblNum" with one field "Num"
of type Long and make it the primary key.
Enter 53 records, 0 through 52 in "Num."
Create 2 combo boxes and 2 text boxes on your form.
1) cmboYear:
rowsource =
SELECT Year(Date())+[tblNum].[Num] AS RptYear
FROM tblNum
ORDER BY Year(Date())+[tblNum].[Num];
2) cmboWeek:
"initial" rowsource:
SELECT [Num]+1 AS YearWeek,
(#1/1/2005#-(Weekday(#1/1/2005#)-1))+[Num]*7 AS WeekStart,
[WeekStart]+6 AS WeekEnd
FROM tblNum
ORDER BY [Num]+1;
Column Count: 3
Column Heads: Yes
Column Widths: 0.7";0.8";0.8"
Bound Column: 1
List Rows: 35
List Width: 2.5"
3) txtStartDate
unbound but locked
4) txtEndDate
unbound but locked
'**** code for form ****
Option Compare Database
Option Explicit
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Dim strSQL As String
Dim lngYear As Long
lngYear = Year(Date)
Me!cmboYear = lngYear
strSQL = "SELECT [Num]+1 AS YearWeek, " _
& "(#1/1/" & lngYear & "#-(Weekday(#1/1/" _
& lngYear & "#)-1))+[Num]*7 AS WeekStart, " _
& "[WeekStart]+6 AS WeekEnd " _
& "FROM tblNum " _
& "ORDER BY [Num]+1;"
Me!cmboWeek.RowSource = strSQL
Me!cmboWeek.Requery
Me!cmboWeek = 1
cmboWeek_AfterUpdate
Exit_Form_Load:
Exit Sub
Err_Form_Load:
MsgBox Err.Description
Resume Exit_Form_Load
End Sub
Private Sub cmboWeek_AfterUpdate()
On Error GoTo Err_cmboWeek_AfterUpdate
Me!txtWeekStart = Me!cmboWeek.Column(1)
Me!txtWeekEnd = Me!cmboWeek.Column(2)
Exit_cmboWeek_AfterUpdate:
Exit Sub
Err_cmboWeek_AfterUpdate:
MsgBox Err.Description
Resume Exit_cmboWeek_AfterUpdate
End Sub
Private Sub cmboYear_AfterUpdate()
On Error GoTo Err_cmboYear_AfterUpdate
Dim strSQL As String
Dim lngYear As Long
lngYear = Me!cmboYear
strSQL = "SELECT [Num]+1 AS YearWeek, " _
& "(#1/1/" & lngYear & "#-(Weekday(#1/1/" _
& lngYear & "#)-1))+[Num]*7 AS WeekStart, " _
& "[WeekStart]+6 AS WeekEnd " _
& "FROM tblNum " _
& "ORDER BY [Num]+1;"
Me!cmboWeek.RowSource = strSQL
Me!cmboWeek.Requery
Me!cmboWeek = 1
cmboWeek_AfterUpdate
Exit_cmboYear_AfterUpdate:
Exit Sub
Err_cmboYear_AfterUpdate:
MsgBox Err.Description
Resume Exit_cmboYear_AfterUpdate
End Sub
'**** end of code *****
In this manner you don't care how Access
can confuse a week number. You are defining
a start and end date for your report, and *your
week numbers* will show every week for the
year your user selects in cmboYear.
That might be one way.....
good luck,
gary
{I just downloaded "Time Has Come Today"
by Chambers Brothers thru iTunes, and above
was generated while listening to it over and
over.....so hopefully no flashbacks interferred
with logic.

}