Solved

DCount using "OR"

Posted on 2016-11-28
4
18 Views
Last Modified: 2016-11-28
I am trying to use a dcount function with an "OR" statement and I am not having much luck.  I am not even sure if or is permissible.

Here is my statement.

Me.SessionNumber = Nz(DMax("SessionNumber", "tblSessions", "[VisId]=" & [Forms]![frmVisits00]![frmVisits01].[Form]![visid] & " AND [SessionType] = 'Group' OR 'Group-Other'")) + 1

For just GROUP it works fine.  for GROUP or GROUP-OTHER it then counts across the entire domain instead of just the VisId.

Thanks
0
Comment
Question by:vmccune
  • 2
4 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 250 total points
ID: 41904059
When I'm using domain functions outside of a ControlSource property, I generally split the critieria and the function itself into two parts, which makes it easier to debug.  In your case, you have to explicitly use the reference to the [SessionType] field.  I also like to wrap each criteria in a set of parenthesis just to make sure the logic is processed the way I expect it to be.

Dim strCriteria as string
strCriteria = "([VisId]=" & [Forms]![frmVisits00]![frmVisits01].[Form]![visid] & ") AND " _
                   & ([SessionType] = 'Group' OR [SessionType] = 'Group-Other')"
debug.print strCriteria
Me.SessionNumber = Nz(DMax("SessionNumber", "tblSessions", strCriteria), 0) + 1
0
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 250 total points
ID: 41904597
When you combine AND and OR in a single expression, you MUST understand the order of precedence.  Your expression will only work correctly if you use parentheses correctly to control the execution order.  Dale gave you the answer but he equivocated rather than making a firm point so I am repeating his suggestion as a requirement.  AND is evaluated before OR so the expression as written was being evaluated as:

(A AND B) OR C

But what you want is:

A AND (B OR C)
0
 

Author Comment

by:vmccune
ID: 41904620
Pasted your code and the strCriteria = section is all red.
0
 

Author Comment

by:vmccune
ID: 41904661
The two answers combined gave it to me.  Thanks!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now