Results 1 to 7 of 7
  1. #1
    JeRz is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2014
    Posts
    33

    Year to Date Query help needed

    Hi Everyone,

    I have a report that prompts for the month in which records are needed that counts the number of Issue Types logged. The report then populates those results at the top with the Issue Type and the total count for that month.

    At the bottom, is a YTD table that counts all records logged up to that point. This report is run on the 5th of each month. How can I modify the YTD query to only include up to the last day of the previous month? Obviously I would still need a running total all year just not including the current mnth's record count up to that point.

    The field nanes I have are:

    -ID (PK)
    -IssueType
    -VisitDate



    Thanks for any assistance. I can provide more info if needed.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    I would use a form to fill out the dates, and the query would read them (instead of prompting)
    for YTD, the txtEndDate box would be:


    txtStartDate ="1/1/" & Year(Date)
    txtEndDate =dateadd("d",-1,month(date) & "/1/" & Year(Date))


    (subtract 1 day from the current month)

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Quote Originally Posted by ranman256 View Post
    I would use a form to fill out the dates, and the query would read them (instead of prompting)
    for YTD, the txtEndDate box would be:


    txtStartDate ="1/1/" & Year(Date)
    txtEndDate =dateadd("d",-1,month(date) & "/1/" & Year(Date))
    I'd also use a form, but I don't think that calculation would handle January correctly. I'd get the last day of the previous month:

    Me.txtEndDate = DateSerial(Year(Date()),Month(Date()),0)

    then get the first day of the year from that:

    Me.txtStartDate = DateSerial(Year(Me.txtEndDate), 1, 1)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    JeRz is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2014
    Posts
    33
    Quote Originally Posted by pbaldy View Post
    I'd also use a form, but I don't think that calculation would handle January correctly. I'd get the last day of the previous month:

    Me.txtEndDate = DateSerial(Year(Date()),Month(Date()),0)

    then get the first day of the year from that:

    Me.txtStartDate = DateSerial(Year(Me.txtEndDate), 1, 1)
    Thank you for the response. A follow up question as I'm still learning things. Would these txtEnd and txtStart dates be columns added to the YTD query and the DateSerial added to the criteria?

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Not, they would be form textboxes used in the query criteria. You'd have a button that populated them and then opened the report.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    JeRz is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2014
    Posts
    33
    Quote Originally Posted by pbaldy View Post
    Not, they would be form textboxes used in the query criteria. You'd have a button that populated them and then opened the report.
    Thank you! Worked perfectly!

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 4
    Last Post: 05-03-2017, 09:48 AM
  2. Replies: 7
    Last Post: 06-07-2015, 11:57 PM
  3. Replies: 4
    Last Post: 01-09-2013, 11:16 AM
  4. Replies: 4
    Last Post: 01-10-2012, 06:26 PM
  5. Replies: 0
    Last Post: 03-25-2011, 02:37 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