Expression in a query

Posted on 2014-01-22
Medium Priority
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.
Question by:SteveL13
  • 3
LVL 14

Expert Comment

by:Bill Ross
ID: 39800074

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


LVL 14

Expert Comment

by:Bill Ross
ID: 39800086

You can also create a field using the expression


but this will be slower.


LVL 14

Expert Comment

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

Accepted Solution

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

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

LVL 41

Assisted Solution

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.

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.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
A Case Study of using the Windows API to provide RS232 communications capability in Access without the use of Active-X controls.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

586 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