Solved

DCount using "OR"

Posted on 2016-11-28
4
48 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 35

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

860 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