Results 1 to 6 of 6
  1. #1
    drewetzel is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2011
    Location
    Austin, TX
    Posts
    34

    Question DCount Error

    Hi Guys,



    I'm using the DCount function to count the number of records in a query where one date/time field is greater than or equal to another date time field and am getting the error below...

    "The expression you entered as a query parameter produced this error: 'Microsoft Office Access can't find the name 'InHomeDate' you entered in the expression'

    This is how I'm using the DCount function...

    DCount("contact_id","Qry_CPC_FDFactor_Calls","[start_date]>=[InHomeDate]")

    Before you ask, InHomeDate is definitely a field in the query, Qry_CPC_FDFactor_Calls.

    Any help would be greatly appreciated.

  2. #2
    CraigDolphin is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Apr 2009
    Location
    Custer, WA, USA
    Posts
    125
    try:

    DCount("contact_id","Qry_CPC_FDFactor_Calls","[start_date]>= #" & [InHomeDate] & "#")

    You have to use # to delimit dates/times in the same way as you'd use quotes to delimit text values. You also need to use the value in the data field, not the name of the field itself, inside the where clause of the dcount function. That's why you use the ampersand operator to build the string, referencing the field name outside of the string part.

    Hopefully that makes sense. Sorry if it's unclear.

  3. #3
    drewetzel is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2011
    Location
    Austin, TX
    Posts
    34
    Thanks Craig. I tried that and it destroyed my database haha. It seems like it worked but the query took about 30 minutes to run. I might need to get a better computer. Anyway I think I found a way around using the DCount function. Thanks for the help though.

  4. #4
    CraigDolphin is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Apr 2009
    Location
    Custer, WA, USA
    Posts
    125
    Domain aggregate functions like dcount do tend to run slow: especially if you're using them to summarize complex queries and subqueries with lots of records in the source tables.

    If you can use SQL to do the same job, it should run a lot faster as a rule.

  5. #5
    drewetzel is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2011
    Location
    Austin, TX
    Posts
    34
    Yeah, I don't know any SQL right now, but I'm learning it. Thanks again for the help.

  6. #6
    pploum is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2014
    Posts
    5
    Hi, I am having a similar problem. I have a small query with 6 money collection dates. I want to rank them, by counting the number of date values that are lower than each record's value. (I later want to use the rank in another function)

    CountLowerValues: DCount("*";"dd_collectiondates";"[dtl_collectiondate] <= #" & [dtl_collectiondate] & "#")
    Click image for larger version. 

Name:	Screen shot 2014-02-13 at 12.51.57 AM.png 
Views:	27 
Size:	18.5 KB 
ID:	15361
    values of [dtl_collectiondate] are 1-apr-2014, 1-may-2014, 1-jul-2014, ... The function returns 0 (zero) for each record, whereas it should be returning 1,2,3, etc
    Click image for larger version. 

Name:	Screen shot 2014-02-13 at 12.52.20 AM.png 
Views:	10 
Size:	15.5 KB 
ID:	15362
    What am I doing wrong?
    Thanks

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

Similar Threads

  1. DCount
    By nsteenhaut in forum Queries
    Replies: 2
    Last Post: 10-04-2011, 05:00 PM
  2. DCount and If
    By Madmax in forum Access
    Replies: 3
    Last Post: 07-28-2011, 06:53 AM
  3. DCount for Multiples
    By Huddle in forum Access
    Replies: 2
    Last Post: 12-21-2010, 08:57 AM
  4. DCount and SQL
    By DSTR3 in forum Queries
    Replies: 3
    Last Post: 12-06-2010, 03:07 PM
  5. Help with Dcount
    By tozey in forum Programming
    Replies: 1
    Last Post: 08-10-2010, 10:53 AM

Tags for this Thread

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