Results 1 to 9 of 9
  1. #1
    cenibyte is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2016
    Posts
    4

    Date format and expression

    I am trying to have the date display by year within a certain date range and display all the data that is required by year. I have built my query and the date is formatted to display the year, program, and amount of entries for each program... But it displays all the entries for the year. Please help.

    Field: Date In By Year: Format$([Nominal Rolls].[Date In],'yyyy')

    Field: Program
    Table: Nominal Roll

    Field: Count of Nominal Rolls: Count(*)

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    My guess is you have Group By in the column with the criteria. Change that to Where. If that isn't it, post the full SQL of the query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    cenibyte is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2016
    Posts
    4
    If I change it to where it removes the criteria and groups all the totals together. How do I get the SQL?

  4. #4
    cenibyte is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2016
    Posts
    4
    -------------------------------------------------------------
    | Date In By Year | Program | Count Of Nominal |
    | | | Rolls |
    -------------------------------------------------------------
    | 2015 | AVOTP | 1 |
    | | | |
    -------------------------------------------------------------
    | 2016 | AVOTP | 21 |
    | | | |
    -------------------------------------------------------------
    | 2016 | CBRN OP | 1 |
    | | | |
    -------------------------------------------------------------
    | 2016 | SF OP | 19 |
    | | | |
    -------------------------------------------------------------
    | 2016 | SCP | 1 |
    | | | |
    -------------------------------------------------------------
    | 2016 | SNIPER | 23 |
    | | | |
    -------------------------------------------------------------
    | 2016 | COT | 8 |
    | | | |
    -------------------------------------------------------------
    | 2016 | CT | 3 |
    | | | |
    -------------------------------------------------------------
    | 2016 | FE | 1 |
    | | | |
    -------------------------------------------------------------
    | 2016 | RES OT | 2 |
    | | | |
    -------------------------------------------------------------
    | 2016 | FA | 1 |
    | | | |
    -------------------------------------------------------------
    | 2016 | IEDD | 1 |
    | | | |
    -------------------------------------------------------------
    | 2016 | CMOT | 1 |
    | | | |
    -------------------------------------------------------------

  5. #5
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    How do I get the SQL?
    If you have done this in Access, just change your query to SQL View and copy and paste the code here.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    With the query in design view, on the ribbon click on the dropdown by the view icon and choose SQL.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    cenibyte is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2016
    Posts
    4
    Quote Originally Posted by pbaldy View Post
    With the query in design view, on the ribbon click on the dropdown by the view icon and choose SQL.
    SELECT DISTINCTROW Format$([Nominal Rolls].[Date In],'yyyy') AS [Date In By Year], [Nominal Rolls].Program, Count(*) AS [Count Of Nominal Rolls]
    FROM [Nominal Rolls]
    GROUP BY Format$([Nominal Rolls].[Date In],'yyyy'), [Nominal Rolls].Program
    HAVING (((Format$([Nominal Rolls].[Date In],'yyyy'))>#4/1/2016# And (Format$([Nominal Rolls].[Date In],'yyyy'))<#3/31/2017#));

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try

    SELECT Format$([Nominal Rolls].[Date In],'yyyy') AS [Date In By Year], [Nominal Rolls].Program, Count(*) AS [Count Of Nominal Rolls]
    FROM [Nominal Rolls]
    WHERE [Nominal Rolls].[Date In]>#4/1/2016# And [Nominal Rolls].[Date In]<#3/31/2017#
    GROUP BY Format$([Nominal Rolls].[Date In],'yyyy'), [Nominal Rolls].Program
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Your "Format$" function are not returning dates, they are returning years (in Text format). So you still want to apply criteria to the underlying dates.

    Try this:
    Code:
    SELECT DISTINCTROW Format$([Nominal Rolls].[Date In],'yyyy') AS [Date In By Year], [Nominal Rolls].Program, Count(*) AS [Count Of Nominal Rolls]
    FROM [Nominal Rolls]
    WHERE (([Nominal Rolls].[Date In]>#4/1/2016#) And ([Nominal Rolls].[Date In]<#3/31/2017#))
    GROUP BY Format$([Nominal Rolls].[Date In],'yyyy'), [Nominal Rolls].Program;

    Edit: Yeah, what Paul said!

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

Similar Threads

  1. Replies: 4
    Last Post: 02-15-2016, 09:12 PM
  2. Replies: 3
    Last Post: 12-02-2014, 07:58 PM
  3. Replies: 3
    Last Post: 08-20-2014, 01:47 PM
  4. Format font in expression
    By Ruegen in forum Programming
    Replies: 3
    Last Post: 10-08-2013, 06:12 PM
  5. Replies: 4
    Last Post: 03-12-2013, 06:49 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