Results 1 to 10 of 10
  1. #1
    nick.h is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    22

    Weekday() to filter results by Monday, Tuesday etc

    Hey guys,



    I have a query that counts all the records that were added in the last week (by looking at a DateAdded field (which automatically populates with a Now()).

    I would like to break down the results further by having the records broken down by Monday, Tuesday, Wednesday, Thursday, and Friday headers.

    Any idea how I would write the logic to do that? I can not wrap my head around the Weekday() function at all yet

    Thanks for your help,
    Nick

  2. #2
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    A)dd a calculated field to your query.

    WD:weekday([DateAdded])
    or if you want to sort on the name,
    WD:weekdayname([DateAdded])

  3. #3
    nick.h is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    22
    It gave me an invalid procedure call???

    Here is the code

    SELECT "Prospecting Calls" AS VisitType, Abs(Sum(VisitDate Between Date()-6 And Date())) AS Week, Abs(Sum(VisitDate Between Date()-29 And Date())) AS [Month], Abs(Sum(VisitDate Between Date()-89 And Date())) AS Quarter, Abs(Sum(VisitDate Between Date()-359 And Date())) AS [Year], WeekdayName([DateAdded]) AS WD
    FROM VisitInfo
    WHERE (((VisitInfo.[VisitDate]) Between Date()-359 And Date()) AND ((VisitInfo.[AddedBy])=GetUser()) AND ((VisitInfo.[FormOfContact])=3))
    GROUP BY "Prospecting Calls", WeekdayName([DateAdded]);

    It is part of a larger union query, but until I get it working I'm jsut trying to fix one bit of it.
    Last edited by nick.h; 12-11-2011 at 03:59 PM. Reason: added sql code

  4. #4
    nick.h is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    22
    Crap, I found out what caused the invalid procedure call. It was me forgetting to take out the code that sorted it by Week, Month, Quarter, and Year.

    What I want to do is get a Count of all records taht were added on Monday, Tuesday, Wednesday etc.

    Here is what I've changed it to so far:

    SELECT "Prospecting Calls" AS VisitType, Weekday(VisitDate) AS WD
    FROM VisitInfo
    WHERE (((VisitInfo.[VisitDate]) Between Date()-6 And Date()) AND ((VisitInfo.[AddedBy])=GetUser()) AND ((VisitInfo.[FormOfContact])=3))
    GROUP BY "Prospecting Calls";

    It doesn't work and I'm horribly confused, lol

  5. #5
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Fair warning ,,, I'm not on my Access box and I'm use the design view

    when doing queries.
    However, there are a couple of things in your SQL that don't look right.

    Quote Originally Posted by nick.h View Post
    Crap, I found out what caused the invalid procedure call. It was me forgetting to take out the code that sorted it by Week, Month, Quarter, and Year.

    What I want to do is get a Count of all records taht were added on Monday, Tuesday, Wednesday etc.

    Here is what I've changed it to so far:

    Is "Prospecting Calls" a field? If so, I'd use [Prospecting Calls].
    So...

    SELECT [Prospecting Calls] AS VisitType, Weekday([VisitDate]) AS WD
    FROM VisitInfo
    WHERE (((VisitInfo.[VisitDate]) Between Date()-6 And Date()) AND ((VisitInfo.[AddedBy])=GetUser()) AND ((VisitInfo.[FormOfContact])=3))
    GROUP BY [Prospecting Calls],[WD];

    It doesn't work and I'm horribly confused, lol
    HTH

  6. #6
    nick.h is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    22
    Actually Prospecting Calls is not a field name. Like I said earlier it is part of a larger union query which sorts different call types and the query adds a column which names the row of results. Does that make sense?

  7. #7
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Yes, your comment does make sense. So if you leave quotes around

    "Prospecting Calls" do you get results?

  8. #8
    nick.h is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    22
    Yea, I haven't had a problem with that.

  9. #9
    nick.h is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    22
    SELECT "Prospecting Calls" AS VisitType, Abs(Count(VisitDate)) AS WD
    FROM VisitInfo
    WHERE (((VisitInfo.VisitDate) Between Date()-359 And Date()) AND ((VisitInfo.AddedBy)=GetUser()) AND ((VisitInfo.FormOfContact)=3))
    GROUP BY "Prospecting Calls WD";

    Here's the current code. Again the rub is I would like to have a count of all records added on last Monday, last Tuesday. Sorry if I'm repeating myself, but I babble when I'm stumped.

  10. #10
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    At the very least, a comma is missing.

    Quote Originally Posted by nick.h View Post
    SELECT "Prospecting Calls" AS VisitType, Abs(Count(VisitDate)) AS WD
    FROM VisitInfo
    WHERE (((VisitInfo.VisitDate) Between Date()-359 And Date()) AND ((VisitInfo.AddedBy)=GetUser()) AND ((VisitInfo.FormOfContact)=3))
    GROUP BY "Prospecting Calls",WD;

    Here's the current code. Again the rub is I would like to have a count of all records added on last Monday, last Tuesday. Sorry if I'm repeating myself, but I babble when I'm stumped.
    However, the rest of the SQL has pieces that don't make sense and I'm afraid we are confusing each other. I suggest that you post the basic SQL query which includes all of the fields which are needed to later sort,group, and total. This query should include the weekday calculated field.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Help with Weekday Function
    By Juan4412 in forum Queries
    Replies: 3
    Last Post: 10-18-2011, 07:14 AM
  2. Weekday Name from a Date
    By Coors in forum Queries
    Replies: 9
    Last Post: 09-26-2011, 03:08 PM
  3. Convert date to weekday overview
    By LarsBoer in forum Forms
    Replies: 3
    Last Post: 09-14-2011, 07:25 AM
  4. cbo to filter results from a query
    By nianko in forum Forms
    Replies: 5
    Last Post: 08-18-2010, 09:43 AM
  5. Weekday excluding weekends
    By jd316632 in forum Queries
    Replies: 3
    Last Post: 05-24-2010, 02:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums