Results 1 to 6 of 6
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097

    What's the expression to be added...........................

    Looking at the snippet screenshot (below) of a queries design view, I need to add, I think, two expressions to the query that returns the number of records where PCCode = "N" and separately the number of records where PCCode = "R"



    I tried this: NofN: Sum([PCCode]=Chr(78)) but I get an error. What's the proper expression to get the counts?

    Click image for larger version. 

Name:	000.jpg 
Views:	12 
Size:	44.3 KB 
ID:	24608

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    Give this a try

    Code:
    SELECT DISTINCTROW [tblMembers].PCCode, Count([tblMembers].PCCode) AS CountOfPCCode
    FROM [tblMembers]
    WHERE PCCode = "N" or PCCode = "R" 
    GROUP BY [tblMembers].PCCode;

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    I will try to incorporate your suggestion into the query, while at the same time breaking up the count approach to produce both a "CountOfPCCodeN" and "CountOfPCCodeR". Something like CountOfPCCodeN: Count([tblMembers].PCCode = 'N') and CountOfPCCodeR: Count([tblMembers].PCCode = 'R'). I'll post back one way or another.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You can Sum an IIf():

    sum(IIf(PCCode = "R", 1,0))
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    I tried your suggestion as an expression, but as you can see in the screenshot it failed.
    Click image for larger version. 

Name:	00.jpg 
Views:	6 
Size:	60.2 KB 
ID:	24618

  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,652
    The Sum makes it a totals query, so you'd want to select that and the appropriate option for each field (Group By, Where, etc).
    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-2016, 01:51 PM
  2. Replies: 5
    Last Post: 09-25-2013, 09:35 AM
  3. Value cannot be added
    By mr_right in forum Access
    Replies: 2
    Last Post: 03-26-2013, 12:56 AM
  4. Replies: 2
    Last Post: 11-20-2012, 03:21 AM
  5. Replies: 4
    Last Post: 10-26-2012, 12:49 AM

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