Results 1 to 3 of 3
  1. #1
    Neologic29 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2013
    Posts
    13

    Help with DCount expressions in macros

    Hello,

    I am so grateful for the help I received with my last question and I have another, possibly more straightforward one. I have a report which I am using the DCount function on a control to return the number of records for a particular query based on criteria for two of the fields. The expression works perfectly on the report but I am trying to use the same expression in an If statement to check and see if there are records and if not, a message pops up saying something like "No records exist" However, when I try to save the macro, the exact same expression (which I copied and pasted from the report control) is unable to be parsed.


    Here is the expression as I tried to enter it (as part of an If/Then statement):



    Code:
    DCount("[Lab Receipt Number]","qryTotal_Tasks_byExaminer","[Examiner]='" & [Forms]![Report Select Form]![cboExaminer] & " ' AND [Date of Report] >= #" & [Forms]![Report Select Form]![txtStartDate] & "# AND [Date of Report]<= #" & [Forms]![Report Select Form]![txtEndDate] & "#")=0
    Is it too long for Access to parse? When I remove the Examiner criteria, it seems to be fine. Maybe there is some VBA code that can do this more easily, but I have used this method for other queries and it works great, although the ones that work only have a date criterion. Any help would be appreciated.

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    Are you getting an error message of some kind, or does it just not work?

    This may or may not be significant, but you have a space before the closing single quote of the Examiner string in the criteria part of the DCount:

    & " ' AND [Date of Report]
    ^

    The ^ marks the extra space.

    See if it works if you remove that space.

    HTH

    John


  3. #3
    Neologic29 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2013
    Posts
    13
    When I attempt to save the macro with that expression, I get a message saying Access cannot parse it. I've tried removing the spaces and that doesn't seem to be the problem. I'll keep working on it and maybe I'll check back here later. Thanks.

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

Similar Threads

  1. Grouping Expressions
    By GraeagleBill in forum Reports
    Replies: 5
    Last Post: 05-10-2013, 05:58 PM
  2. Expressions in Form
    By Deb4566 in forum Access
    Replies: 7
    Last Post: 03-08-2013, 12:18 PM
  3. command buttons - expressions vs macros
    By tess in forum Access
    Replies: 1
    Last Post: 04-03-2012, 02:28 PM
  4. Repeat Expressions
    By welshmpf in forum Access
    Replies: 8
    Last Post: 09-06-2011, 09:41 AM
  5. Combining Two DCount expressions in one
    By nmodhi in forum Forms
    Replies: 1
    Last Post: 02-26-2010, 10:49 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