# Every third (3) week on Thursday...

Hello All,

I have no idea how to begin to have my application retrieve records based on the following:

In the options section of my application the app user can choose to have a [reminder] set to notify them (say) "Every 3 weeks on a Thursday.' I have the following fields created.

Start Date, Number of Weeks, chkSun, chkMon, chkTue, chkWed... all seven days.

How can I recall [as a reminder] this data [Every 3 weeks on a Thursday] ?

Please remember that number of weeks and days will change per the app user.

###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Firstly, There's no point in pre-calculating the reminder dates. How far forward would you calculate, and what if the user changes his/her options?

I would have another field 'Next Reminder', and would calculate it every time the reminder triggered, and every time the options were changed. then the logic for triggering a reminder is simply ' is it today? ' or :
if Next Reminder = date() then .....

Then I would trim the day variables to a single integer where 1 = Sunday and 7 = Saturday (say Wday).

Then the calculation becomes:

Next Reminder = date() + (Number of weeks * 7)
Today = DatePart("w", date())
if Wday - Today < 0 then     Next Reminder = Next Reminder + 7
Next Reminder = Next Reminder + Wday - Today

.. Any Use??
.. Alan
Commented:

ie

Author Commented:
OK guys,

I'll need a little time to digest this stuff. I'm get back with you soon - I hope :).

Thanks,
Commented:
Hi,
My previous comment was written 'on the fly'. Just to prove it worked, icopied the pseudocode into a VB project, corrected syntax errors, and it ran first time:

Dim NextReminder As Date
Dim WDay As Integer ' Day of week 1=Sun, 2=Mon etc ... 7 = Sat
Dim Today As Integer
Dim NumberOfWeeks As Integer

NumberOfWeeks = 3 ' Required reminder 3 Weeks
WDay = 2                 '     "              "       on Monday
NextReminder = Date + (NumberOfWeeks * 7) 'Calculate date n weeks ahead (current day)
Today = DatePart("w", Date)  ' find todays day number
If WDay - Today < 0 Then NextReminder = NextReminder + 7 ' * See Note
NextReminder = NextReminder + WDay - Today ' Add the difference between required day and today
MsgBox NextReminder

* Note This line is only required if reminder is wanted '3 weeks NEXT Monday' In My tests I checked today (4/12/2003 if you're English, or 12/4/2003 if you're American):

With this line NextReminder was 29/12/03 (12/29/03)
Without this line NextReminder was 22/12/03 (12/22/03)

.. Alan

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:

Dim WDay As Integer ' Day of week 1=Sun, 2=Mon etc ... 7 = Sat
Dim NumberOfWeeks As Integer

NumberOfWeeks = 3 ' Required reminder 3 Weeks
WDay = 2                 '     "              "       on Monday
MsgBox DateAdd("d", NumberOfWeeks * 7 + WDay - Weekday(Now) + 7, Date)
Author Commented:
Lots of stuff to work with. Thanks to all!