Results 1 to 2 of 2
  1. #1
    rachello89 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2012
    Posts
    15

    Access won't count correctly

    I have four tables in question:

    tblEnrollments
    tblEnrollment Product


    tblProducts
    tblServiceType

    An enrollment can have many enrollmentproducts because students can change their particular plan for that enrollment. I am trying to create a query that counts the number of enrollments that have products with service type "C." The answer should be somewhere in the 50s; the answer that Access gives is 76. I believe what is happening is, Access is counting the enrollment products. For instance, if an enrollment has 3 products, it counts it as 3. It should be counted as 1. I am stumped about how to fix this. Thanks in advance for your help! Below is the SQL statement:

    SELECT Count(tblEnrollments.EnrollmentID) AS CountOfEnrollmentID
    FROM tblServiceType INNER JOIN (tblProducts INNER JOIN (tblEnrollments INNER JOIN tblEnrollmentProduct ON tblEnrollments.EnrollmentID = tblEnrollmentProduct.EnrollmentID) ON tblProducts.ProductID = tblEnrollmentProduct.EnrollmentProduct) ON tblServiceType.ServiceID = tblProducts.ServiceID
    WHERE (((tblEnrollments.EnrollmentEndDate) Is Null) AND ((tblServiceType.ServiceID)="C")) OR (((tblEnrollments.EnrollmentEndDate)>[Start Date]) AND ((tblServiceType.ServiceID)="C"));

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You have to group by the product.

    I would alter the SELECT clause of your first query as follows and just have that query filter your dataset:


    query name: Q1
    SELECT tblEnrollmentProduct.EnrollmentProduct, tblEnrollments.EnrollmentID
    FROM tblServiceType INNER JOIN (tblProducts INNER JOIN (tblEnrollments INNER JOIN tblEnrollmentProduct ON tblEnrollments.EnrollmentID = tblEnrollmentProduct.EnrollmentID) ON tblProducts.ProductID = tblEnrollmentProduct.EnrollmentProduct) ON tblServiceType.ServiceID = tblProducts.ServiceID
    WHERE (((tblEnrollments.EnrollmentEndDate) Is Null) AND ((tblServiceType.ServiceID)="C")) OR (((tblEnrollments.EnrollmentEndDate)>[Start Date]) AND ((tblServiceType.ServiceID)="C"));

    Then create a new query based on the above

    SELECT Q1.EnrollmentProduct, Count(Q1.EnrollmentID) as CountOfEnrollmentID
    FROM Q1
    GROUP BY Q1.EnrollmentProduct

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

Similar Threads

  1. Replies: 3
    Last Post: 01-03-2012, 12:28 PM
  2. Replies: 2
    Last Post: 06-18-2011, 09:55 AM
  3. Count Distinct in Access
    By georgerudy in forum Access
    Replies: 1
    Last Post: 11-28-2010, 01:24 PM
  4. Access DB distinct count
    By anziga in forum Queries
    Replies: 3
    Last Post: 10-12-2010, 02:20 PM
  5. Subform not showing correctly
    By ricardo9211 in forum Forms
    Replies: 1
    Last Post: 08-27-2009, 07:49 AM

Tags for this Thread

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