Assuming that you are referring to calendar weeks (Sunday being the first day of the weeks as it appears on standard calendars), you can determine which week any given date falls in using the following code:
Public Function Week(ByVal InputDate as Date) As Integer
Week = 2+Int((Day(InputDate)-1-Weekday(InputDate))/7)
End Function
Explanation:
This is simplified code, without any error handling. It assumes that you pass it a valid date.
The Int() function in VB6 returns the integer portion of a number (the next lower integer). Therefore, Int(3.1) returns 3. For negative numbers, it works the same, but gives what is probably an unexpected result. Int(-3.1) returns -4 (the next lower integer). However, this works precisely the way we want it to for this calculation.
Day(InputDate) returns the day of the month (4 in the example of 4 May 2003).
Weekday(InputDate) returns the day of the week (based on your computer settings, with Sunday = 1 by default). You can force the first day of the week to be what you want, but to keep the example simple, I didn't. In the example of 4 May 2003, it would return vbSunday which = 1 by default.
Any date is at least in the first week of the month. Any date that is larger than the day of the week is in at least the second week of the month. Therefore, by using week 2 as a base and using the Int() capabilities as described above (after dividing by 7 days per week), I subtract 1 from 2 for all dates where Day(InputDate) <= Weekday(InputDate). Subtracting 1 from Day(InputDate) takes care of the = portion.
Anyway, I haven't actually run the code, but put it through the paces. I think it will provide what you asked.
Good luck. BlackburnKL