2

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?

dwitvliet
  • 7,242
  • 7
  • 36
  • 62
Arjun
  • 25
  • 4

2 Answers2

0

You've got too many double quotes:

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

I removed the one after the second hashmark, and one in front of the word Status.

Essentially, the third part of the DCount function is an SQL WHERE clause without the word "WHERE", and you must follow the same syntax and structure rules as with standard SQL.

scottmcd9999
  • 214
  • 1
  • 3
0

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"
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418