Solved

return count of number of Sundays in any given month

Posted on 2004-08-30
2
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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