Results 1 to 8 of 8
  1. #1
    rdr910 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    9

    DCount Items in query field


    Need a little help - I have made a report that gets its information from a query that gets its results from a form search. I use the following code to get the total number of records that the search brings up: =DCount("*","[mainquery]") using a text box on the report. This does work perfectly. Now I want to get the results from a field for a count of certain items and have it appear in a text box on the report. I am using the following code but gives an error: =DCount("TS","[mainquery]","[OVERALLSATISFACTION]") - I am trying to find all items that are "TS" in that field and have that number returned to the text box on the report.

    Someone please help!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849

  3. #3
    rdr910 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    9
    i am getting an error when i try to run this from a report. DCount("*", "mainquery", "SatDriver = TS")

    using * as the expression to count all records. Mainquery is the query and SatDriver is the field i am trying to get the count of "TS" from.

    What am I doing wrong?

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    Don't see anything obvious.

    Try
    DCount("*", "mainquery", "SatDriver = 'TS'") if SatDriver is a text value

  5. #5
    rdr910 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    9
    That worked! Thanks! One last question, how would i find the "null" values with using the code above?

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849

  7. #7
    rdr910 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Posts
    9
    The code is giving me an error

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,849
    What is the error message?

    Try
    DCount("*", "mainquery", "SatDriver Is Null") Is Null is the sql statement expected by DCount

    IsNull() is a vba function which is not used or expected with DCount or other aggregate functions.

    Sorry for any inconvenience.

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

Similar Threads

  1. Dcount query
    By ramdandi in forum Queries
    Replies: 1
    Last Post: 12-27-2011, 01:30 PM
  2. Replies: 2
    Last Post: 09-30-2011, 04:57 AM
  3. Using Dcount on an Autonumber Field
    By rfs in forum Forms
    Replies: 0
    Last Post: 03-17-2011, 10:04 AM
  4. Replies: 1
    Last Post: 02-03-2011, 11:19 AM
  5. VBA DCount() with variable field name
    By drh in forum Programming
    Replies: 2
    Last Post: 07-13-2010, 12:36 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