Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Expression in a query

Posted on 2014-01-22
5
Medium Priority
?
213 Views
Last Modified: 2014-01-22
Using query designer I have this code:

TouringCount: Abs(Count([ID]) And [PublicActivityCode]="GT")

Which doesn't work.  I'm trying to count the records (ID) where PublicActivityCode] = "GT" or "ST".

It needs to be an expression because I have more of these types of fields to add.
0
Comment
Question by:SteveL13
[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
  • 3
5 Comments
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39800074
Hi,

Change the query to group by
Put [ID] as a count field in the query
Make criteria  [PublicActivityCode]="GT"

Regards,

Bill
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39800086
Hi,

You can also create a field using the expression

dcount("ID",yourtable,"PublicActivityCode='GT'")

but this will be slower.

Regards,

Bill
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39800089
FYI - ABS is not required.  Count can never be <0.
0
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 1000 total points
ID: 39800182
You can use:

TouringCount: Sum(Abs([PublicActivityCode]="GT" Or [PublicActivityCode]="ST"))

/gustav
0
 
LVL 39

Assisted Solution

by:PatHartman
PatHartman earned 1000 total points
ID: 39800409
Functions in a query operate over the domain of the recordset.  So, Count(ID) returns a count of non-null values of ID contained in the recordset.  It cannot be constrained by criteria.  The simplest way to get a count of all values for a particular field is with this type of query:

Select PublicActivityCode, Count(*) As RecCount
From YourTable
Group By PublicActivityCode;

You will get a list like:
GT, 2345
ST, 123
AB, 445
xx, 3939
, 2
, 3

Notice the last two.  One will be the count of null values and the other will be the count of ZLS values.

If you want all the values returned as a single row, create a crosstab of the totals query.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

722 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