?
Solved

DCount criteria not working properly

Posted on 2009-04-15
4
Medium Priority
?
328 Views
Last Modified: 2013-11-27
Hi experts,

I dun know why the following Dcount function is not giving me the correct count:

When I manually check from the table, I realized the criteria [Status] = 'a1' OR [Status] = 'a2' is not being read.

Can anyone help me resolve the issue here?
Many Thanks
myCount = Nz(DCount("[Number]", "TempOthers2", "[Type] = 'XFER' AND [Booking] = 'bbbb' " _
    & "AND ([Status] = 'a1' OR [Status] = 'a2') AND (Left([aField], 13) = 'UBSSG.LON.OTC' OR Left([aField], 15) = 'BARCSSG.LON.OTC' " _
    & "OR Left([aField], 13) = 'BNPSG.PAR.OTC') OR (Left([bField], 13) = 'UBSSG.LON.OTC' OR Left([bField], 15) = 'BARCSSG.LON.OTC' " _
    & "OR Left([bField], 13) = 'BNPSG.PAR.OTC')"), 0)

Open in new window

0
Comment
Question by:LizzJ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 2000 total points
ID: 24146212
I'm guessing that what you really want is..

myCount = Nz(DCount("[Number]", "TempOthers2", "[Type] = 'XFER' AND [Booking] = 'bbbb' " _
    & "AND ([Status] = 'a1' OR [Status] = 'a2') AND ((Left([aField], 13) = 'UBSSG.LON.OTC' OR Left([aField], 15) = 'BARCSSG.LON.OTC' " _
    & "OR Left([aField], 13) = 'BNPSG.PAR.OTC') OR (Left([bField], 13) = 'UBSSG.LON.OTC' OR Left([bField], 15) = 'BARCSSG.LON.OTC' " _
    & "OR Left([bField], 13) = 'BNPSG.PAR.OTC'))"), 0)
I've added extra brackets around the big Or clauses.
'a2') AND ((Left.............OTC'))"), 0)
0
 

Author Comment

by:LizzJ
ID: 24146254
dun quite get it though. why need extra brackets?
0
 

Author Comment

by:LizzJ
ID: 24146264
it works though.... weird
0
 
LVL 77

Expert Comment

by:peter57r
ID: 24146363
Your structure was:

a=1 and b=2 and (c=3 or d=4) and (e=5 or f=6) or (g=7 or h=8)
AND has precedence over OR so this was read as:

( a=1 and b=2 and (c=3 or d=4) and (e=5 or f=6) ) or (g=7 or h=8)

so all of the first conditions must be true Or one of the last

I assumed yu always wanted the first set of conditions to be true and at least one of the big OR clauses to be true so you need to force  Access to read it that way.
a=1 and b=2 and (c=3 or d=4) and ( (e=5 or f=6) or (g=7 or h=8) )
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question