Question Set date to this coming friday (Task form)

Core

Registered User.
Local time
Today, 12:44
Joined
May 27, 2008
Messages
79
Hello,

I am creating a task management section of my client management database. When I create a task I would like set the due date with a buttons, for example, due tomorrow, due in 2 days. One button I would like to set the date to Friday of the current week.

Any idea's how I would do this in VBA?

Regards,
 
I think dateadd("d",6- weekday(date),date) will give you the friday for the current week based off of today's date, this assumes the first day of the week is Sunday.
 
I would suggest using a set of variables.
Set one variable to equal todays date.

Code:
Dim TodaysDate as date
todaysdate = Format(now(),"mm/dd/yyyy") 'or some variation on that

Then have different option buttons. Each button would create a date based on that buttons function. create a variable to hold the new date and use something like this to add 3 days.
Code:
nextdate = DateAdd("d", 3, todaysdate)
'Then set your duedate field to equal the variable.
me.duedate.value = nextdate

For the Friday You could create a select case statement.

Code:
    TestDate = Format(Date(), "dddd, mmm d yyyy")
    
Select Case Testdate

Case "Monday*"
nextdate = DateAdd("d", 4, testdate)

Case "Tue*"
nextdate = DateAdd("d", 3, testdate)
Case "Wed*"
nextdate = DateAdd("d", 2, testdate)
Case "Thu*"
nextdate = DateAdd("d", 1, testdate)
Case "Fri*"
nextdate = testdate 'OR maybe on friday you would want it to add 7 days

End Select

Hope that helps
 
I think dateadd("d",6- weekday(date),date) will give you the friday for the current week based off of today's date, this assumes the first day of the week is Sunday.

thats a good one

i've done it before by successively incrementing the date until i reach a vbfriday!

i will check but it looks like this may not handle a saturday correctly - it looks like it backs up a day, instead of going forward 6 days?
 
indeed on a saturday it would back up a day, but who would be scheduling stuff on a Saturday? ;)
 
Hi -

This should work for any weekday.

Code:
? dateadd("d", -weekday(date())+6 , date())

To produce the following Friday

Code:
? dateadd("d", -weekday(date())+6 + iif(weekday(date())= 7, 6, 0) , date())

HTH - Bob
 
Last edited:

Users who are viewing this thread

Back
Top Bottom