How to create YTD query without entering the Dates?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bre035
    New Member
    • Sep 2007
    • 42

    #1

    How to create YTD query without entering the Dates?

    I am creating a Year to Date report. Typically, I create a query to allow the ability to enter the beginning and end date, but I want to automate this without entering the date.

    I have criteria in query >[Enter beginning Date]<DATE(). However, I wanted to know is there a Date format for the beginning of the year.

    I attempted to DateModified >01/01 <Date(), but this always saves as the current date.
  • mshmyob
    Recognized Expert Contributor
    • Jan 2008
    • 903

    #2
    YOu could do what you are doing with the "01/01/" and then append just the year from the current date by using the YEAR function for date manipulation.

    Code:
    dteYTD="01/01/" & year(Date)

    cheers,

    Comment

    • Bre035
      New Member
      • Sep 2007
      • 42

      #3
      Thank you but when I get the date then attempt add it as a criteria for DateModified for YTD Date Range - Access states datatypes are different.

      DateYTD is saving as a test field.

      Comment

      • mshmyob
        Recognized Expert Contributor
        • Jan 2008
        • 903

        #4
        Show me your query.

        cheers,

        Comment

        • Bre035
          New Member
          • Sep 2007
          • 42

          #5
          My initial query set the DateYTD field:
          Code:
          SELECT tbl_CLLData.[CALL TYPE], tbl_CLLData.[RECORD ID], tbl_CLLData.[CALL RESULT], tbl_CLLData.CLL_Type, tbl_CLLData.DateModified, "01/01/" & Year(Date()) AS DateYTD INTO tbl_CALLTPE_MGT
          FROM tbl_CLLData;
          My second query performs the comparison where I get the Data Type mismatch:
          Code:
          SELECT tbl_CALLTPE_MGT.[CALL TYPE], tbl_CALLTPE_MGT.[RECORD ID], tbl_CALLTPE_MGT.[CALL RESULT], tbl_CALLTPE_MGT.CLL_Type, tbl_CALLTPE_MGT.DateModified INTO tbl_CALLTPE_MGT_1YTD
          FROM tbl_CALLTPE_MGT
          WHERE (((tbl_CALLTPE_MGT.DateModified)>"DateYTD"<Date()));
          Last edited by NeoPa; Oct 29 '10, 02:42 PM. Reason: Please use the [code] tags provided.

          Comment

          • mshmyob
            Recognized Expert Contributor
            • Jan 2008
            • 903

            #6
            I would expect that to produce an error.

            Last line (your WHERE clause) should be something like

            Code:
            WHERE tbl_CALLTPE_MGT.DateModified > #DateYTD# AND tbl_CALLTPE_MGT.DateModified < Date();
            Note: I have not tested this but please try this to see if it helps.

            cheers,
            Last edited by NeoPa; Oct 29 '10, 02:42 PM. Reason: Please use the [code] tags provided.

            Comment

            • Bre035
              New Member
              • Sep 2007
              • 42

              #7
              What I did was trim the DateModified field to get the Year, then criteria set to Year(Date()), which yeilds the results I needed for the current year records.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32669

                #8
                Assuming [DateModified] cannot be a future date, you can simply say :
                Code:
                WHERE (Year([DateModified]) = Year(Date))
                The existing code, while pretty close, would surely ignore anything dated on the current date.

                Comment

                Working...