PC Review


Reply
Thread Tools Rate Thread

Count YTD workdays

 
 
Secret Squirrel
Guest
Posts: n/a
 
      13th Apr 2009
I have a table "tblWorkdaysCalendar" that lists all the work days for
2008-2011. I'm trying to count the number of workdays for 2009 YTD through
the last full month. How can I do that in my query? Right now if I select
just a year from my form it gives me all the workdays for that given year. If
I choose a month and year then I get just that month. The month & year
seleciton together works fine and returns just that month's workdays but I
can't figure out how to count workdays YTD through the last full month. Any
help would be greatly appreciated.

SELECT Count(WorkdaysCalendar.CalDate) AS CountOfCalDate,
Format([CalDate],"mmmm") AS Months, Format([CalDate],"yyyy") AS Years
FROM WorkdaysCalendar
GROUP BY Format([CalDate],"mmmm"), Format([CalDate],"yyyy")
HAVING
(((Format([CalDate],"mmmm"))=[Forms]![frmSelectAbsenteeism]![cboMonth]) AND
((Format([CalDate],"yyyy"))=[Forms]![frmSelectAbsenteeism]![cboYear])) OR
(((Format([CalDate],"yyyy"))=[Forms]![frmSelectAbsenteeism]![cboYear]) AND
(([Forms]![frmSelectAbsenteeism]![cboMonth]) Is Null));


Thanks
SS

 
Reply With Quote
 
 
 
 
Danny J. Lesandrini
Guest
Posts: n/a
 
      13th Apr 2009
So the question is, how do I get the last day of the current month?

I usually do one of these.

This one gives you the first day of NEXT month
WHERE [CalDate] < DateSerial(Year(Date()),Month(Date()),1)


This one gives you the last day of THIS month
WHERE [CalDate] <= DateSerial(Year(Date()),Month(Date()),1) -1

You're using the HAVING clause, but I don't see why you need it.
Actually, I don't see why you need the combo boxes. If you want
the WHERE through the end of the CURRENT month, then the
boxes are supurflous.
--
Danny J. Lesandrini
(E-Mail Removed)
www.amazecreations.com


"Secret Squirrel" <(E-Mail Removed)> wrote ...
>I have a table "tblWorkdaysCalendar" that lists all the work days for
> 2008-2011. I'm trying to count the number of workdays for 2009 YTD through
> the last full month. How can I do that in my query? Right now if I select
> just a year from my form it gives me all the workdays for that given year. If
> I choose a month and year then I get just that month. The month & year
> seleciton together works fine and returns just that month's workdays but I
> can't figure out how to count workdays YTD through the last full month. Any
> help would be greatly appreciated.
>
> SELECT Count(WorkdaysCalendar.CalDate) AS CountOfCalDate,
> Format([CalDate],"mmmm") AS Months, Format([CalDate],"yyyy") AS Years
> FROM WorkdaysCalendar
> GROUP BY Format([CalDate],"mmmm"), Format([CalDate],"yyyy")
> HAVING
> (((Format([CalDate],"mmmm"))=[Forms]![frmSelectAbsenteeism]![cboMonth]) AND
> ((Format([CalDate],"yyyy"))=[Forms]![frmSelectAbsenteeism]![cboYear])) OR
> (((Format([CalDate],"yyyy"))=[Forms]![frmSelectAbsenteeism]![cboYear]) AND
> (([Forms]![frmSelectAbsenteeism]![cboMonth]) Is Null));
>
>
> Thanks
> SS
>



 
Reply With Quote
 
John Spencer MVP
Guest
Posts: n/a
 
      13th Apr 2009
For the current month and year

SELECT Count(CalDate)
FROM tblWorkdaysCalendar
WHERE CalDate Between DateSerial(Year(Date()),1,1) and
DateSerial(Year(Date()),Month(Date()),0)

Using your controls for input to get the year and month

WHERE CalDate Between DateSerial([Forms]![frmSelectAbsenteeism]![cboYear],1,1)
AND DateSerial([Forms]![frmSelectAbsenteeism]![cboYear],
[Forms]![frmSelectAbsenteeism]![cboMonth],0)

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Secret Squirrel wrote:
> I have a table "tblWorkdaysCalendar" that lists all the work days for
> 2008-2011. I'm trying to count the number of workdays for 2009 YTD through
> the last full month. How can I do that in my query? Right now if I select
> just a year from my form it gives me all the workdays for that given year. If
> I choose a month and year then I get just that month. The month & year
> seleciton together works fine and returns just that month's workdays but I
> can't figure out how to count workdays YTD through the last full month. Any
> help would be greatly appreciated.
>
> SELECT Count(WorkdaysCalendar.CalDate) AS CountOfCalDate,
> Format([CalDate],"mmmm") AS Months, Format([CalDate],"yyyy") AS Years
> FROM WorkdaysCalendar
> GROUP BY Format([CalDate],"mmmm"), Format([CalDate],"yyyy")
> HAVING
> (((Format([CalDate],"mmmm"))=[Forms]![frmSelectAbsenteeism]![cboMonth]) AND
> ((Format([CalDate],"yyyy"))=[Forms]![frmSelectAbsenteeism]![cboYear])) OR
> (((Format([CalDate],"yyyy"))=[Forms]![frmSelectAbsenteeism]![cboYear]) AND
> (([Forms]![frmSelectAbsenteeism]![cboMonth]) Is Null));
>
>
> Thanks
> SS
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count the Number of Workdays Rocetman Microsoft Excel Misc 5 2nd Mar 2010 04:59 PM
How can I count workdays in Access? =?Utf-8?B?V2VuZHkgSA==?= Microsoft Access 2 10th May 2005 12:16 AM
count workdays =?Utf-8?B?YWNjZXNzIGNvbmZ1c2U=?= Microsoft Access Queries 1 28th Dec 2004 05:01 AM
count workdays buddy Microsoft Access 3 28th Jul 2004 07:49 AM
Count # Workdays b/t two dates? =?Utf-8?B?ZXhjZWx1c2VyQGhvdG1haWwuY29t?= Microsoft Excel Worksheet Functions 3 13th Nov 2003 09:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:38 PM.