Dcount question

Eljefegeneo

Still trying to learn
Local time
Today, 08:26
Joined
Jan 10, 2011
Messages
902
I have the following DCount Statement that works fine:
Code:
  If DCount("*", "qryCountA", "[SNumber] = " & Forms!frmS![SNumber] '& " And [Changes] = 'Rate' ") >= 1
But I cannot figure out how to and an "OR" to the second criteria. That is, I want to be able to select the record if [Changes] = "Rate" or [Changes] = "Time". Is it possible to have a second "OR" condition in this statement? Or is there a better way of doing this?
 
I'm surprised that code works-- You have an unmatched single quote in there (before the second &).

You can add as many OR statements as you like. The key is grouping your criteria with parenthesis. When you mix ANDs and ORs you need to make sure they group together properly. This is what it should look like:

Criteria1 AND (Criteria2 OR Criteria3)

Be sure to use parenthesis around the items that go together, because the above is logically different than this:

Criteria1 AND Criteria2 OR Criteria3
 
Last edited:
You have to make sure the criteria string resolves into something sql will accept. Example:

Code:
OrdersCount = DCount("[ShippedDate]", "Orders", "[ShipCountry] = '" & strCountry & "' AND [ShippedDate] > #" & dteShipDate & "#")
 
Plog:
You are correct, that was a typo error. I have tried your suggestion about using the parenthesis around the conditions, but I can't get the syntax correct. The Single quote and double quote marks are very confusing. But, sometimes just a little prodding works.

This now seems to work fine:
Code:
 If DCount("*", "qryCounA", "[SNumber] = " & Forms!frmS![SequenceNumber] & " And ([Changes] = 'Rate'  OR  [Changes] = 'Time' Or [Changes] = 'Name')") >= 1 Then

And I do thank you. But another strange anomaly appears. Since the statement is so long, I tried to break it up using an underline.

Code:
 If DCount("*", "qryCounA", "[SNumber] = " &  Forms!frmS![SequenceNumber] & " And  _  ([Changes] = 'Rate'  OR   [Changes] = 'Time' Or [Changes] = 'Name')") >= 1 Then

I get an error at the "(" on the second line and the error message:

"Expected List Separator or )". What am I doing wrong? The Underline _ usually works fine. Why not in this case?
 
You are using it inside your string. It needs to be outside and you need an ampersand in front of it:

str_Example="This is first part of the string" & _
" and this is the second part"
 

Users who are viewing this thread

Back
Top Bottom