Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word count in access queries

Status
Not open for further replies.

superseba888

Programmer
Aug 14, 2006
4
BE
Hello,

I would like a new field which could contain the word count of another field (memo or text).

A thing which can me help to show in a form and report, the field ABC coutains 18 words.

Has anybody a solution for me ?

Thanks in advance !
Vince
 
I read this some time ago:
Len([YourField]) - Len(Replace([YourField]," ","")) + 1

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
hello dhookom, thanks for your time.

I'm still a newbie, here's what I tried.

1/
On the query, I made a new query field with your formula, like this :
newname : Len([YourField]) - Len(Replace([YourField]," ","")) + 1

2/
On the form, I made a new field, with this :
= Len([YourField]) - Len(Replace([YourField]," ","")) + 1



Of course I replaced YourField by the correct field name.


However, the reply given is : syntax incorrect,and I can't go further.

Any advice ?

Thank for your help !
Vince
 
Is [YourField] ever Null? If so, you may need to use:
WordCount : Len([YourField] & "") - Len(Replace([YourField] & ""," ","")) + 1

Some versions of Access haven't supported Replace() in a query.

What happens if you set your SQL view of a query to
Code:
SELECT msysObjects.Name, Len([Name])-Len(Replace([Name]," ",""))+1 AS WordCount, msysObjects.Type
FROM msysObjects;


Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Hello,

The field is not null.

The problem is, when inserted on the query, acces even allow me to go further, unless I have deleted the sentence.

It says that the syntax is incorrect, that I have omitted an operator, entered an invalid character or enter text without delimiting it with "".

Aout your sql code, I really don't know what to do with this. I don't know access so good ...

Can you please explain ?

Thanks again for your time !
vince
 
Open a new blank query and select View->SQL. Then copy and paste the code into the SQL View window. Then select View->Datasheet to see what happens.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top