Solved

return count of number of Sundays in any given month

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

830 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