That's kind of where I started. In order for
that to work I would need to get every date
that was between the 2 dates, then use the
DatePart Function to find out what week it
was.
Hunh?
I think we're going in the right direction but
missing some vital piece.
Ayup! Missing some vital piece.
You get the week number of the first date, the week number of the second
date, and use them to generate a list of the week numbers between them, if
that is what you need. Of course, there would be some questions, like "Do
you want a list of the week numbers? How do you want them saved, if at all?"
For simplicity, I didn't put all the hoops you'd have to jump through to
accomodate dates in different years (but you could accommodate that) or
dates more than 100 weeks apart (but you could accommodate that, too)
As to how you generate the list, here's some code that works for a couple of
values, complete with lots of Debug.Prints to show what's going on (not
"exhaustively" tested), and a little extra code to start storing the values
in the first member of a 100 member array (since I didn't know what you
wanted to do with the numbers once you had them):
Function ListWeeks(datStart As Date, datEnd As Date) As Integer
Dim aWeeks(1 To 100) As Integer
Dim i As Integer, j As Integer, k As Integer
Debug.Print "Start Week: "; CInt(DatePart("ww", datStart))
Debug.Print "End Week: "; CInt(DatePart("ww", datEnd))
j = 1 - CInt(DatePart("ww", datStart))
Debug.Print j
For i = CInt(DatePart("ww", datStart)) To CInt(DatePart("ww", datEnd))
aWeeks(j + i) = i
Debug.Print "Aweeks("; j + i; ")= "; i
k = k + 1
Next
ListWeeks = k
End Function
Paste it into a standard module, and run it from the Immediate Window with:
? ListWeeks(#6/16/2005#,#12/16/2005#)
as your first test values.
It doesn't look quite as intimidating if you strip out all the Debug.Print
stuff:
Function SimpWeeks(datStart As Date, datEnd As Date) As Integer
Dim aWeeks(1 To 100) As Integer
Dim i As Integer, j As Integer, k As Integer
j = 1 - CInt(DatePart("ww", datStart)) 'adjustment to make array index
For i = CInt(DatePart("ww", datStart)) To CInt(DatePart("ww", datEnd))
aWeeks(j + i) = i
k = k + 1
Next
SimpWeeks = k
End Function
Larry Linson
Microsoft Access MVP