If you use the ISO numbering of weeks, you can use this function which takes a year and a week number as both the first and the last dates of a calendar year may belong to week number 52/53:
CODE
Public Function ISO_DateOfWeek( _
ByVal intYear As Integer, _
ByVal bytWeek As Byte, _
Optional ByVal bytWeekday As Byte = vbMonday) _
As Date
' Calculates date of requested weekday in a week of
' a year according to ISO 8601:1988 standard.
'
' Notes: Years less than 100 will be handled as
' two-digit years of our current year frame.
' Years less than zero returns a zero date.
' A weeknumber of zero returns the requested
' weekday of the week before week 1.
'
' 2000-12-17. Cactus Data ApS, Gustav Brock.
' The fourth of January is always included in
' the first week of year intYear.
Const cbytDayOfFirstWeek As Byte = 4
' Number of days in a week.
Const cbytDaysOfWeek As Byte = 7
' Month of January.
Const cbytJanuary As Byte = 1
Dim datDateOfFirstWeek As Date
Dim intISOMonday As Integer
Dim intISOWeekday As Integer
Dim intWeekdayOffset As Integer
' No specific error handling.
On Error Resume Next
If intYear > 0 Then
' Weekday of Monday.
intISOMonday = WeekDay(vbMonday, vbMonday)
' Date of fourth of January in year intYear.
datDateOfFirstWeek = DateSerial(intYear, cbytJanuary, cbytDayOfFirstWeek)
' Weekday of fourth of January in year intYear.
intISOWeekday = WeekDay(datDateOfFirstWeek, vbMonday)
' Calculate offset from Monday in first week of year intYear.
intWeekdayOffset = intISOMonday - intISOWeekday
' Weekday of requested weekday.
intISOWeekday = WeekDay(bytWeekday, vbMonday)
' Calculate offset from requested weekday in first week of year intYear.
intWeekdayOffset = intWeekdayOffset + intISOWeekday - intISOMonday
' Date of requested weekday in first week of year intYear.
datDateOfFirstWeek = DateAdd("d", intWeekdayOffset, datDateOfFirstWeek)
' Date of requested weekday in requested week of year intYear.
datDateOfFirstWeek = DateAdd("ww", bytWeek - 1, datDateOfFirstWeek)
End If
ISO_DateOfWeek = datDateOfFirstWeek
End Function
You can use it like this where txtWeek and txtYear are the two textboxes for the parameter input (txtYear may be given a default value of the current year):
Me!txtDateFirst = ISO_DateOfWeek(Me!txtYear, Me!txtWeek, vbMonday)
Me!txtDateLast = ISO_DateOfWeek(Me!txtYear, Me!txtWeek, vbFriday)
As for picking the week number from a combobox, that's a good idea which screams for a List function (no queries or prepopulated tables) - one of the gems of Access):
CODE
Public Function ListWeeknumbers( _
ctl As Control, _
lngNum As Long, _
lngRow As Long, _
lngCol As Long, _
intCode As Integer) As Variant
' Creates a list of week numbers of current year according to the ISO 8601:1988 standard.
' 2007-07-09. Gustav Brock, Cactus Data ApS, CPH
Select Case intCode
Case acLBInitialize ' Initialize.
ListWeeknumbers = True
Case acLBOpen ' Open.
ListWeeknumbers = Timer ' Unique number as a check.
Case acLBGetRowCount ' Count of rows. The highest weeknumber in the current year.
ListWeeknumbers = ISO_WeekCount(Date)
Case acLBGetColumnCount ' Count of colums.
ListWeeknumbers = 1
Case acLBGetColumnWidth ' Width of column.
ListWeeknumbers = -1 ' Use default width of column.
Case acLBGetValue ' Fetch data.
ListWeeknumbers = lngRow + 1 ' First row is 0.
Case acLBEnd ' Close.
' ' Nothing to do.
End Select
End Function
Look up the on-line help for how List functions work and how to apply. A little learning may be needed but you won't regret.
/gustav