Page 1 of 4 1234 LastLast
Results 1 to 15 of 54
  1. #1
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234

    Count values in a column on a table


    Seems simple enough, but I want a query that will return a value of how many times a customer ID is found in the "reference" column.

    So basically, I'm looking to write a query that is = Count the number of times this client's ID is found in the Reference column of tblClient.

    I just don't know the right syntax to do that.

  2. #2
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    I tried both =Count([“Reference”],[”tblClient”],[ClientID]) and =DCount([“Reference”],[”tblClient”],[ClientID]), but I got #Name? as an error message.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    Count(*)

    DCount("*","tblClient","Reference=" & [ClientID])

    Brackets [] if used would be within the quote marks.
    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.

  4. #4
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    When I put =DCount("*","tblClient","Reference=" & [ClientID]) in the control source, I'm getting #Error.

    Why can't anything with this Frankenstein DB be easy?

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    I don't know your db so can't say.

    If you want to provide for analysis, follow instructions at bottom of my post.
    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.

  6. #6
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    I've provided it a few times, and, due to the errors (I had to delete far too much of the DB), you weren't able to do much with it.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    Oh, that one.

    The DCount() syntax provided is correct.

    That expression is in textbox on form? Is ClientID a field in the form RecordSource? Is it a text or number type?
    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.

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    First you have
    but I want a query that will return a value of how many times a customer ID is found in the "reference" column.
    then you say "control source"....
    When I put =DCount("*","tblClient","Reference=" & [ClientID]) in the control source, I'm getting #Error.
    Confusing....Which one do you want?

    Look at post #3 again.
    June's example is the syntax for a query and does not have an equal sign! In a query, do not use the equal sign.
    In the query, it should look something like:
    Code:
    ClientCount: DCount("*","tblClient","Reference=" & [ClientID])

    If you use an equal sign, that is for the control source for a control on a form.
    Code:
    = DCount("*","tblClient","Reference=" & [ClientID])
    Plain as mud, right???


    EDIT:
    I just looked at the table and the field "Reference" is a TEXT type field. That requires delimiters.
    So the syntax for a query
    Code:
    ClientCount: DCount("*","tblClient","Reference = '" & [ClientID] & "'")
    and a control
    Code:
    = DCount("*","tblClient","Reference = '" & [ClientID] & "'")

  9. #9
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    Ok, Somewhat clearer than mud.

    I initially wanted to do a query, but then I realized it wasn't necessary.

    I put a textbox bound to ClientID on frmClient and it works fine: pulling the ClientID from tblClient. ClientID is a field on tblClient and the type is AutoNumber. Reference is also a field on tblClient, its type is Text.

    I put a new textbox directly underneath the textbox that is bound to ClientID, and for its control source, I have =DCount("*","tblClient","Reference=" & [ClientID]).

    As per Ssanfu's suggestion, I changed it to
    =DCount("*","tblClient","Reference = '" & [ClientID] & "'"), and Voila!

    Thank you yet again, Ssanfu and June7. You two are proving invaluable.

    Now for the tricky part: I'd like to double click on the number that results from the code in the textbox, and have it show which specific clients were referred by this particular client.

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    I am confused and baffled. Why would there be two fields in tblClient with same data? Why does Reference have client ID and ClientID also has client ID? Are there really two tables involved?

    A textbox cannot be bound to a field and also have an expression in ControlSource.
    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.

  11. #11
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    One table is involved: tblClient. 2 fields are involved: ClientID and Reference. I used the wrong verbiage. The textbox has an expression, and is not bound to anything.

    I apologize for the confusion.

  12. #12
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    Ok, what I'm trying to do, is create a new query that will look at tblClient in the Reference field, find all instances of the ClientID that's in the ClientID box on frmClient, and display the names and ClientIDs of each client that the specific client referred.

    I started making it, then confused myself.

  13. #13
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    To put a picture to what I'm doing, see that in the picture below, I have client ID, which is taken form tblClient. Clients referred, which is derived by =DCount("*","tblClient","Reference = '" & [ClientID] & "'") as the control source.

    For this particular client, they referred 14 clients. In the box below, I want to see which specific clients this client referred, and how many events they've had.

    I know a query can do this, but I don't quite know how to make it happen.

    Click image for larger version. 

Name:	new client.png 
Views:	14 
Size:	2.7 KB 
ID:	21483

  14. #14
    bradp1979 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Location
    San Francisco, CA
    Posts
    234
    Hopefully the errors you encountered previously won't affect this particular project.
    Attached Files Attached Files

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    Two tables not found in relinking - tblEmployee_bu and tblInsCert. No errors now.

    Looking at tblClient, understand now. ClientID 11150 has Reference of 3396. What does 3396 mean? Did you delete ClientID record 3396? So I should put some legitimate values into Reference field? I presume not all clients will have referral from another client.

    What form do you want to do the count on and which textbox?

    If you want to be able to do a self-join of tblClients so the client info for Reference can be viewed (as might be desired in a report), Reference will have to be a number field.
    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.

Page 1 of 4 1234 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 14
    Last Post: 07-13-2015, 12:47 PM
  2. Replies: 8
    Last Post: 10-03-2013, 08:11 AM
  3. Transform Column values in Table
    By Mnelson in forum Access
    Replies: 1
    Last Post: 06-11-2012, 03:06 PM
  4. 3 values in 1 Column - Get Count of Each Value
    By Ghoztrider in forum Queries
    Replies: 1
    Last Post: 01-09-2012, 03:26 PM
  5. Replies: 2
    Last Post: 11-18-2009, 06:49 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