Gibberish,
Bear with me on this. Whenever I want to do anything with ranges of
dates
or ranges of numbers, I create a table with the numbers 0 through 9, then
a
query from that that contains the numbers 0 through 999 (larger if I
think
I'll need it). With this table and query, I can accomplish what you are
looking for relatively simply.
1. I have a table (tbl_Numbers) that contains a single long integer field
(lngNumber) and contains the values 0 through 9
2. The query (qry_Numbers) looks like:
SELECT Hundreds.lngNumber * 100 + Tens.lngNumber * 10 + Ones.lngNumber as
lngValues
FROM tbl_Numbers Hundreds, tbl_Numbers Tens, tbl_Numbers Ones
3. Then, to do what you want, you need to do something like the
following.
This query has a subquery that develops the list of dates for the year
and
month the user inputs. The outer query limits the list to those where
the
Weekday( ) function returns a value that matches the user provided value,
and
the Count () gives you a total count of the days in the month that fall
on a
specific weekday.
SELECT Count(dtDay) as PerMonth
FROM (
SELECT DateSerial([Enter year],[Enter month],1)+[lng_Value] AS dtDay
FROM qry_Numbers
WHERE DateSerial([Enter year],[Enter
month],1)+[lng_Value]<DateSerial([Enter
year],[Enter month]+1,1)) as MonthDays
WHERE weekday(dtDay,1) = [What day of the week (numeric starting on
Sunday)]
If I was going to do this for use in an application, I'd have a text box
for
the year, and combo boxes for the month and day of the week on a form. I
would then change the references in the query below to these controls,
and
would have another control that displays the number by using:
=DLOOKUP("PerMonth", "qryCount_Of_Weekday_in_Month")
HTH
Dale
--
Email address is not valid.
Please reply to newsgroup only.
Gibberish said:
I have tried several Data functions to determine how to count the
total number of "Thursday's" in a given month. For instance:
If I choose to find out how many "Thursday's" are in the month of
September in any given year, how can I find this within a query by not
writing a
complex code in VB?- Hide quoted text -
- Show quoted text -