default date to the following Monday

Fisky

New member
Local time
Today, 05:34
Joined
Mar 11, 2014
Messages
9
Hi All,
I'm a first time user and just gettinting to grips with Access so here it goes.

I have a textbox in a form. What I want it to do is to display the following weeks Monday date. Sounds simple but requires you to know the Monday dates in advance :confused:

Fisky
 
Hello Fisky, Welcome to AWF :)

Copy the following code into a Standard module, The Save it with a name that is not getMonDate. The Compile the code. Use it as the Default value of the text box where you want to get eh Monday date.
Code:
Public Function getMonDate(Optional inputDate) As Date
[COLOR=Green]'********************
'Code Courtesy of
'  Paul Eugin
'********************[/COLOR]
    If IsMissing(inputDate) Then inputDate = Date
    
    getMonDate = inputDate - Weekday(inputDate) + 9
End Function
 
You can use the Weekday function, the below code calculate the next Monday, where by me Monday is the first day of a week.
Code:
Date - Weekday(Date, vbMonday) + 8
 
Thanks for the promp reply Paul. I've tried this, coped the code to Module1 and placed the '=Module1' in the text box Default Box but I get an error '#Name?'. Any suggestions?
 
Last edited:
No, copy the code into Module1, save it as Module1, compile the code. In the text box use =getMonDate()
 
Sorry. Paul. closed the form and reopended it and it stops with and errror @ line 3 of the code: 'getMonDate = ...' . Am I missing a field in '(Optional inputDate)'?
 
What is the error? Error Number and Description.
 
Hi Paul. Found this code on another thread. It gives the Monday of that week (starting Sunday). Can you modifiy this code?

=Date() - (DatePart("w", Date(), 2, 1)-1)
 
=Date() - (DatePart("w", Date(), 2, 1) - 1) + 7

Should return next monday

Or if you prefer:
=Date() - (DatePart("w", Date(), 2, 1)) + 6
 
Thanks for that, it didn't work but found that :

=Date() - (DatePart("w", Date(), 4, 1)) + 6 :) works!

I'm using Access 2003 and just wounder if that has been the problem?
 
Made a too quick a short cut....

=Date() - (DatePart("w", Date(), 2, 1)) + 8

the 2 in this datepart work with monday as the start of the week (i.e. be day 1)
If you put 4 it makes Wednesday be start of the week (be day 1)

It kindoff doesnt really matter.
 

Users who are viewing this thread

Back
Top Bottom