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

ID: Q210498


The information in this article applies to:
  • Microsoft Access 2000

Moderate: Requires basic macro, coding, and interoperability skills.


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, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


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:


  2. 
    Option Explicit 
  3. Type the following procedure:


  4. 
    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# 

Additional query words:

Keywords : kbprg kbdta AccCon KbVBA
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: July 6, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.