Finding Specific days in the year

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Unfortunately I have no code to show as I have no idea how to best tackle my
situation.

I am trying to create a schedule, lets say between January 1 and March 31 of
2006. I need to be able to schedule people for each Sturday at one specific
time and each Sunday at 2 different times. What is the best way to get the
date of the first Saturday, then move to the sunday, then find the next
saturday, etc... in VB code? I can do everything else I need to do except
move through the different days.

Thanks in advance
 
Here's a little function that'll give you the date for any "generic" day of
the month:

Function GetDate( _
WhatYear As Long, _
WhatMonth As Long, _
WhatWeekDay As Long, _
WhatWeekDayOfMonth As Long) As Date

Dim dtmFirstOfMonth As Date

dtmFirstOfMonth = _
DateSerial(WhatYear, WhatMonth, 1)

GetDate = DateAdd("w", _
(WhatWeekDayOfMonth - 1) * 7, _
DateAdd("d", _
(WhatWeekDay - _
Weekday(dtmFirstOfMonth + 7) Mod 7, _
dtmFirstOfMonth) _
)

End Function

Just in case the parameters aren't obvious, WhatYear is the year, WhatMonth
is the month number (January = 1, February = 2...), WhatWeekDay is the
number of the weekday (Sunday = 1, Monday = 2 and so on: the same as the
intrinsic constants vbSunday, vbMonday, ...) and WhatWeekDayOfMonth is the
order number of the weekday (1 = first occurrence of that weekday in the
month, 2 = second occurence of that weekday in the month and so on)

If you need the ability to know something like "the last Thursday of
February, 2005" or "the second last Tuesday of May, 2006", I wrote about
this in my June, 2005 "Access Answers" column in Pinnacle Publication's
"Smart Access". Unfortunately, I haven't got that column up on my website
yet (my contract with Pinnacle doesn't let me put my columns online until 6
months after they've been published), but it should be available for free
download (complete with sample database) at
http://www.accessmvp.com/djsteele/SmartAccess.html sometime this weekend.
(Sorry, but it's a little too long to type out here!)
 
Back
Top