Count # of Characters of a certain type in a record

B

BlueWolverine

Hello,
MS Access 2003 on XP Pro.

I have a table with a field in which I list several Codes, in a comma
separated fashion. I am sure the first thing you are going to tell me is,
"Why do you have a single field with comma separated list of values." Call
it convenience and I don't know how many fields I'd need to put one in to
each. And I don't want to fold it.

Anyway, I want to count the number of commas in a "cell" (Cell being an
entry for a record in a particular field. call it a row-column intersection.)

Is there any good way to count the number of times a comma shows up in Field
X for each record?

Thanks,
 
J

John Spencer

The following should work in Access 2000 (fully patched) or later.

Field: CountCommas: Len(YourField)- Len(Replace(NZ(YourField<""),",",""))

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
M

Marshall Barton

BlueWolverine said:
MS Access 2003 on XP Pro.

I have a table with a field in which I list several Codes, in a comma
separated fashion. I am sure the first thing you are going to tell me is,
"Why do you have a single field with comma separated list of values." Call
it convenience and I don't know how many fields I'd need to put one in to
each. And I don't want to fold it.

Anyway, I want to count the number of commas in a "cell" (Cell being an
entry for a record in a particular field. call it a row-column intersection.)

Is there any good way to count the number of times a comma shows up in Field
X for each record?


NumCommas = Len(field) - Len(Replace(field, ",", ""))
 

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