Default Value to a Specific Date

  • Thread starter Thread starter Jon M.
  • Start date Start date
J

Jon M.

Hi everybody.
I come once again looking for guidance from the masters. I have a form with
a simple date field called WeekOf. The user enters the begining date of the
week then completes the rest of the attached subforms. The begining of the
week is always Monday. What I would like to do is to set the default value
of my field WeekOf to be the next coming Monday. So if I opened the form
today, the default value for that field on a new record would be 6/8/09. If
I opened it tomorrow it'd still be the same, but if on 6/8/09 I opened a new
record the value would be 6/15/09. It feels like this should be possible but
I'm lost. I don't know much about DateAdd and DateDiff other than they
exist. As alway I appreciate any help I can get.
 
Hi Jon

Copy the function below and paste it into a standard module:

========== start code ==============
Public Function NextMonday(Optional ByVal DateFrom As Date) As Date
If DateFrom = 0 Then DateFrom = Date
NextMonday = DateFrom + 8 - Weekday(DateFrom, vbMonday)
End Function
========== end code ===============

It will return you the date of the Monday following any given date (default
is today).

Now, set the DefaultValue property of your WeekOf textbox to:
=NextMonday()
 
Back
Top