Search code examples
ms-access-2010dcount

Control Source property: Dcount: Unable to specify Multiple Condition


I have two commands in Microsoft Access 2010 that works fine individually:

=DCount("*","Order","DATE = #" & [Forms]![formOrder]![DATE] & "#")

=DCount("*","Order", "STATUS = 'ST." & [Forms]![formOrder]![StatusType] & "'")

However, when combining them it doesn't work:

 =DCount("*","Order","DATE = #" & [Forms]![formOrder]![DATE] & "#" AND "STATUS = 'ST." & [Forms]![formOrder]![StatusType] & "'" )

Any explanation and a possible workaround would be much appreciated?


Solution

  • The third argument to domain aggregate functions like DCount() is a string that is essentially the WHERE clause of a SQL statment without the WHERE keyword. In trying to combine your criteria you are attempting to AND two strings together, which is not valid. That is, your criteria parameter is

    "Condition1" AND "Condition2"
    

    which won't work. Instead, you need to put the AND within the string itself

    "Condition1 AND Condition2"
    

    In other words, instead of

    "Field1 = value1" AND "Field2 = value2"
    

    you need to use

    "Field1 = value1 AND Field2 = value2"