Solved

return count of number of Sundays in any given month

Posted on 2004-08-30
2
249 Views
Last Modified: 2012-06-27
I'd like to put code in a textbox's control source that returns the total number of Sundays in any given month. For instance, this month would return the #5. Thanks
0
Comment
Question by:robsking
2 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 500 total points
ID: 11938066
This is a function that uses a brute force method:

Function GetSundays(dtDate As Date) As Long
Dim I As Long

For I = DateSerial(Year(dtDate), Month(dtDate), 1) To DateSerial(Year(dtDate), Month(dtDate) + 1, 0)
   If Weekday(I, vbSunday) = 1 Then GetSundays = GetSundays + 1
Next
End Function

Set the control source of your textbox to:
=GetSundays(Date())

to get the number of Sundays in the current month, or a date in any particular month to retrieve the number of Sundays in that month.
0
 

Author Comment

by:robsking
ID: 11938091
Works for me. Thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now