How do i count a total of a value using a From and to date.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lambden10
    New Member
    • May 2015
    • 13

    How do i count a total of a value using a From and to date.

    Help Please, (Access 2003)

    I have made the expression for my count which i have done successfully (as you can see on my screenshots), but i would like to use a from and to date as we would run this query on a weekly basis.

    The idea is to know how many enquiries each of our lawyers have had each week.

    Is this possible?
    If so could someone help me with the expression please.

    Regards
    Kyle


    [imgnothumb]http://bytes.com/attachment.php? attachmentid=83 01[/imgnothumb]

    [imgnothumb]http://bytes.com/attachment.php? attachmentid=83 02 [/imgnothumb]
    Attached Files
    Last edited by zmbd; May 11 '15, 04:59 PM. Reason: [Lambden10{Adding Additional info}][z{placed images inline}]
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    You would use the Between statement on your date field. For example
    Code:
    Between #5/1/2015# And #5/7/2015#
    You can also replace the explicit dates with references to controls on a form.

    Comment

    • Lambden10
      New Member
      • May 2015
      • 13

      #3
      Thank you,

      would it only pick up the date if it was on the table i was doing the query on.

      Bearing in mind i have set up the relationships on my tables.

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        As long as the table that has the Date field is included in the query, then you can use it in the criteria.

        Comment

        • Lambden10
          New Member
          • May 2015
          • 13

          #5
          Oh right okay i got it now, thank you for your help its much appreciated.

          Comment

          • Lambden10
            New Member
            • May 2015
            • 13

            #6
            Hi,

            Sorry to bother you again, i have tried the expression but i keep getting this error:

            "The expression you entered contains invalid syntax"
            "You may have entered a comma without a preceding value or identifier"

            Comment

            • Seth Schrock
              Recognized Expert Specialist
              • Dec 2010
              • 2965

              #7
              Please post the SQL for your query (inside CODE tags) so that I can look at it.

              Comment

              • Lambden10
                New Member
                • May 2015
                • 13

                #8
                Code:
                SELECT Count("AH") AS [F/E]
                   ,Between #2/20/2015# And #2/24/2015# 
                      AS Expr1
                FROM [Conveyancing Enquiries] 
                   INNER JOIN [Conveyancing F/E Totals] 
                      ON [Conveyancing Enquiries].ID 
                         = [Conveyancing F/E Totals].ID;
                It would not let me exit becuase of this error so i have had to take out Between, thats seems to work but i get -1 as the result and this definately isn't accurate.
                Last edited by zmbd; May 11 '15, 05:01 PM. Reason: [z{placed the required formatting. Please see the Forum Posting rules and FAQ}{stepped SQL for readability}]

                Comment

                • Seth Schrock
                  Recognized Expert Specialist
                  • Dec 2010
                  • 2965

                  #9
                  The Between statement goes in the WHERE clause and it needs to know what field it is checking. For example, if your date field is called EnquiryDate, your query would look like this:
                  Code:
                  SELECT Count("AH") As [F/E]
                  FROM [Conveyancing Enquiries] INNER JOIN [Conveyancing F/E Totals] ON [Conveyancing Enquiries].ID = [Conveyancing F/E Totals].ID
                  WHERE EnquiryDate Between #2/20/2015# And #2/24/2015#

                  Comment

                  • Lambden10
                    New Member
                    • May 2015
                    • 13

                    #10
                    It now looks like this, is this correct?
                    Code:
                    SELECT Count("AH") AS [F/E]
                    FROM [Conveyancing Enquiries] 
                       INNER JOIN [Conveyancing F/E Totals] 
                          ON [Conveyancing Enquiries].ID
                             =[Conveyancing F/E Totals].ID
                    WHERE ((([Conveyancing Enquiries].Date) 
                       Between #2/20/2015# And #2/24/2015#));
                    Last edited by zmbd; May 11 '15, 05:02 PM. Reason: [z{placed the required formatting. Please see the Forum Posting rules and FAQ}{stepped SQL for readability}]

                    Comment

                    • Lambden10
                      New Member
                      • May 2015
                      • 13

                      #11
                      I have ran the query and it does now seem to be pulling through the information i need, i am just going to try a different date just to confirm.

                      Comment

                      • Lambden10
                        New Member
                        • May 2015
                        • 13

                        #12
                        Yes all seems okay now once again thank you for your help.

                        Sorry for being a pain :)

                        Comment

                        • Seth Schrock
                          Recognized Expert Specialist
                          • Dec 2010
                          • 2965

                          #13
                          This is how we all learn :)

                          Comment

                          • zmbd
                            Recognized Expert Moderator Expert
                            • Mar 2012
                            • 5501

                            #14
                            You might want to update your SQL to use parameters instead of having to hard code this all of the time:

                            Use parameters in queries and reports

                            and a slightly different viewpoint:
                            How to use the query by form (QBF) technique in Microsoft Access

                            and the always useful Allen Browne:
                            Limiting a Report to a Date Range

                            and here's a generic example based on a query I run in-house using the form...
                            Code:
                            SELECT TestDate
                               , ReadDate, Resample
                               , Passing, TestingResult1
                               , LotNo
                            FROM tableA
                            WHERE (((ReadDate) 
                               Between 
                                  [Forms]![Form_PullDates]![Text_Start] 
                               And 
                                  [Forms]![Form_PullDates]![Text_End]))
                            ORDER BY TestDate;
                            The form has logic behind it to check for proper date format, that start is an older date than end that they two dates are not the same etc...

                            Comment

                            • Lambden10
                              New Member
                              • May 2015
                              • 13

                              #15
                              Hi,

                              I have tried running the expression to count a particular value from a field (F/E Field) i want to calculate how many times a certain F/E has been entered but when i run the expression

                              Count ("PM")

                              It just counts how many records are in the table altogether rather than just one individual, is it the expression i am entering wrong or just the way the tables are set up.

                              Regards
                              Kyle

                              Comment

                              Working...