DateAdd

Experts,

I have this form.
It is a Tasks Form.
There is a date field with control source [DueDate]

I continually need to choose Monday as the DueDate and I want to make this a little quicker.  

How can I modify this:
Me.Due_Date = Date + 1
to always default to Monday's date (3/19/2012) if I press the button?

Lets say if today is 3/15/2012 and if I click the button then the [DueDate] will change to Moday, which is 3/19/2012.  But, of course I could be on any day such as Tuesday, Wed, etc... so I cant hardcode it like I did in the above (Me.Due_Date = Date + 1)

Any ideas?  thank you
pdvsaProject financeAsked:
Who is Participating?
 
Gustav BrockConnect With a Mentor CIOCommented:
You can use this generic function:
Public Function DateNextWeekday( _
  ByVal datDate As Date, _
  Optional ByVal bytWeekday As Byte = vbMonday) _
  As Date

' Returns the date of the next weekday, as spelled in vbXxxxday, following datDate.
' 2000-09-06. Cactus Data ApS.
    
  ' No special error handling.
  On Error Resume Next
  
  DateNextWeekday = DateAdd("d", 7 - (WeekDay(datDate, bytWeekday) - 1), datDate)
    
End Function

Open in new window

So:

Me.Due_Date = DateNextWeekday(Date, vbMonday)

/gustav
0
 
pdvsaProject financeAuthor Commented:
I wouldnt need the code to be too smart menaing that if I was already on Monday...
0
 
pdvsaProject financeAuthor Commented:
Me.Due_Date = Date + 1   is used just to add a day to the current day
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
als315Commented:
No points :)
Set default value for this field to Gustav's function and you will need no code in events
0
 
burrcmCommented:
You can build it in a query. Fields -

Adate:#your date# - or a lookup wherever

Weekday: Weekday([Adate],2)

Monday: DateAdd("d",-[Weekday]+1,[Adate])

Sunday: DateAdd("d",-[Weekday]+7,[Adate])

Prev Sunday: DateAdd("d",-[Weekday],[Adate])

Chris B
0
 
pdvsaProject financeAuthor Commented:
very nice.  That worked perfectly.  

thank you for the expert help!
0
 
Gustav BrockCIOCommented:
You are welcome!

/gustav
0
All Courses

From novice to tech pro — start learning today.