Article ID: 210498 - Last Review: October 11, 2006 - Revision: 2.2

ACC2000: Function to Get Date of Monday Prior to Current Day

This article was previously published under Q210498
Moderate: Requires basic macro, coding, and interoperability skills.

Expand all | Collapse all

SUMMARY

This article describes a function that you can use to find the date of the Monday prior to the current day.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

MORE INFORMATION

The following function determines Monday's date according to the following criteria:
  1. If the current date is Tuesday through Sunday, it yields the date of the prior Monday.
  2. If the current day is Monday, it returns the current date.
  3. If the date is Null or is not a valid date, it returns Null.
To create this function, follow these steps:
  1. Create a module and type the following line in the Declarations section if it is not already there:
    Option Explicit
  2. Type the following procedure:
    Function GetMonDate(CurrentDate)
       If VarType(CurrentDate) <> 7 Then
          GetMonDate = Null
       Else
          Select Case Weekday(CurrentDate)
             Case 1       ' Sunday
                GetMonDate = CurrentDate - 6
             Case 2       ' Monday
                GetMonDate = CurrentDate
             Case 3 To 7  ' Tuesday..Saturday
                GetMonDate = CurrentDate - Weekday(CurrentDate) + 2
           End Select
       End If
    End Function
To test the function, type the following line in the Immediate window, and then press ENTER:
? GetMonDate(#4/30/93#)
Note that the following result will be displayed in the Immediate window:
   #4/26/93#

APPLIES TO
  • Microsoft Access 2000 Standard Edition
Keywords: 
kbhowto kbprogramming KB210498
 

Article Translations