Results 1 to 8 of 8
  1. #1
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501

    Get number or each value in query

    I would like to run a query that looks at an invoice and counts the number of each unique codes.

    I have tried by adding the table, then the field that will be used as the search criteria and then using an iif statement to create the two fields.



    Fields: invoice created fields: NumberOf7, NumberOf1

    Numberof7:IIF([RespCode]=7,count([RespCode],0) and then to get the other number Numberof1:IIF([RespCode]=1,count([RespCode],0)

    but when I run it i get the error "your query does not include the specified expression 'invoice' as part of an aggregate function.

    I am trying to do this because in a form based on a summary query I want to be able to show the number of 7 an 1's but if i add it to the query it will just create another line.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    ?? Suggest you show us the details of what you are trying to do and what you are working with.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    make Q1 to pull data to get unique codes, set property: UNIQUE VALUES = TRUE
    usu: select distinct [code] from table

    make Q2 on Q1 to count them.

  4. #4
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501
    I am not really sure how to show you the details.

    I have a continuous form that is populated from a totals query. I want to keep one line per invoice so if I add resp code to it (and there are 1's and 7's) it will show two lines and I don't want that. I just want to be able to notify the user if any of the detail records for a summary line ( which could be 2-50 detail lines) has a RepsCode of 7.

    So the notification can come on the form some way , i am trying to get a dcount working right now, or maybe in a subquery that counts each of them individually

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,568
    Why can't you do it in the query?
    Here I show the amount of records whose amount is less than 100 and 100 or more for various clients.

    It appears to work correctly?

    Code:
    SELECT Transactions.Description, Sum(Transactions.Amount) AS SumOfAmount, Sum(IIf([Amount]<100,1,0)) AS Less100, Sum(IIf([Amount]>=100,1,0)) AS Greater100
    FROM Transactions
    GROUP BY Transactions.Description;
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501
    I am trying to do it in the query using this

    Resp7: DCount("tbl_Repairs","RespCode","InvoiceNumber = '" & [InvoiceNumber] & "' AND [UpdatedResponsibilityCode] = 7")

    InvoiceNumber is a field in the query but UpdatedResponsibilityCode is not but that shouldn't matter because I am specifying the value right?

    It gives me #Error

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,568
    Join the table tblrepairs with your table and try like I did?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    tagteam is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    501
    Sorry guys, it is Friday.

    It does work but I switched the expression and the domain. I have set it right and it is now working.

    Resp7: DCount("updatedresponsibilitycode","tbl_ImportedRe pairs","InvoiceNumber = '" & [InvoiceNumber] & "' AND [UpdatedResponsibilityCode] = 7")

    Thanks for the help

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

Similar Threads

  1. Replies: 2
    Last Post: 01-05-2018, 04:35 PM
  2. Replies: 2
    Last Post: 08-04-2017, 12:37 PM
  3. Replies: 2
    Last Post: 10-12-2016, 05:48 PM
  4. Sequence number in query use a starting number
    By fgwapo in forum Programming
    Replies: 1
    Last Post: 09-21-2014, 12:44 AM
  5. Replies: 6
    Last Post: 07-25-2011, 01:54 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