Results 1 to 8 of 8
  1. #1
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63

    Count unique customers in report header

    I have a order report for products where I am trying to include how many unique customers ordered a particular product as a customers name may appear twice in the report. The report is populated by a form filter specifying what product to list and the order dates.



    Utilizing the first product in the list, Alice Mutton, two customers have ordered the product twice and should only be included in the count once. The module for the report that I copied successfully counts the unique customers and places the value in and IDCount field in the footer. I don't want the field to appear in the footer but actually in the header.

    What I cannot execute is placing that in the header as well. I tried to copy the field into the header but for some reason it just comes up blank.
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Options:

    1. Create a query called CustomerCount:
    SELECT DISTINCT CustomerID FROM [Ship Report];
    Then in the ControlSource of textbox:
    =DCount("*", "CustomerCount")

    2. Create a function that opens a recordset of the Ship Report query using the sql from option 1 and gets the count of records in the recordset then call that function from textbox. I tried to do this but VBA in your mdb is not cooperating.


    BTW, advise no spaces or special characters/punctuation (underscore is exception) in names.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63
    Good deal. Perhaps my mdb had a corruption somewhere which is why the vba isn't working. At any rate what would the vba look like? I'm not sure how to create a function for other objects in the db.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Option 1 works just fine. Is simple and doesn't need VBA.

    The code I tried for Option 2 is like:

    Function CustomerCount()
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT DISTINCT CustomerID FROM [Ship Report];")
    CustomerCount = rs.RecordCount
    End Function

    The function code could be in the report module or a general module.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63
    Should CurrentDb be switched out for the name of my db and is CustomerCount an unbound field on the report?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    CurrentDb is an intrinsic constant and no do not substitute. CustomerCount is not a field anywhere, it is just the name of the function. Can call the function from textbox ControlSource, same as calling any function - such as the DCount().

    Did you try Option 1?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    hithere is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Sep 2011
    Posts
    63
    Yes I tried Option 1 and it does count the distinct IDs. However, I am using the same report for multiple reports to display data. What I've noticed is employing
    SELECT DISTINCT CustomerID FROM [Ship Report]; Then in the ControlSource of textbox: =DCount("*", "CustomerCount") will supply me with unfiltered results not limited by parameters. When a region combo box is added to the form fillter to view proudct orders by region all customers are tallyed in the customercount field not just those with orders for the product in the selected region.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Try:

    SELECT DISTINCT CustomerID, RegionID FROM [Ship Report];

    or

    SELECT CustomerID, RegionID FROM [Ship Report] GROUP BY CustomerID, RegionID;

    Then include filter in the DCount:

    =DCount("*", "CustomerCount", "RegionID=" & [RegionID])
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Export First Page of Report for Each Unique Header
    By ertweety in forum Programming
    Replies: 3
    Last Post: 06-05-2012, 06:23 PM
  2. Access Unique Count
    By spherehunter in forum Programming
    Replies: 5
    Last Post: 05-17-2012, 11:42 AM
  3. Unique queries - Unique Count
    By bigfish in forum Queries
    Replies: 7
    Last Post: 03-14-2012, 01:28 PM
  4. Replies: 11
    Last Post: 12-09-2010, 10:55 PM
  5. Count of Unique Values
    By vsmk in forum Queries
    Replies: 2
    Last Post: 03-14-2010, 12:07 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