Counting characters in a string

C

cb

I'm trying to create a query that will count the number of records in a table having an entry in a field that is x number of characters long. Any help out there?
 
J

J. Goddard

Hi -

Use a "Totals" query. At its very simplest, it will use two fields, the
field you are interested in checking, and any other field (you can put
the same field in twice if you want)

When you click the totals option (the Greek Sigma - it looks sort of
like a capital "E"), you will see another row displayed in the query,
labelled "Total:"

In the criteria box of the field you want to check, put this:

len(trim([Yourfield]))=x , where "YourField" is the name of the field,
and in the "total" box of that field, select "Where" from the dropdown
list (instead of the default "Group By")

Then, in the other field of the query, change the value in the "Total"
box from "Group By" (the default) to Count

This should do it for you.

In VBA, the SQL for a select query might be:

Select count(*) from [YourTable] where len(trim([FieldName]))=x

Hope this helps

John.

P.S. Be aware that len(trim([field])) will count embedded blanks, but
not leading or trailing ones, and that [field] should be text type.

J.
 
F

fredg

I'm trying to create a query that will count the number of records in a table having an entry in a field that is x number of characters long. Any help out there?

Add a new column to the query grid.
ChrCount:Len([FieldName])

As criteria for this column write:
=x
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top