Solved

return count of number of Sundays in any given month

Posted on 2004-08-30
2
255 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

810 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