473,379 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Count only certain word in memo

Hi,

How I can count certain word in memo field?

For example I have 15 words in one field and "PLUMING" word repeats in
it 3 times. So I would like my code give me number three as the
answer.

Any help with it will be kindly,
Alex
Nov 13 '05 #1
3 2595
Assuming you're using Access 2000 or newer, here's a nifty approach:

Private Function CountInstances( _
ByVal ToSearch As String, _
ByVal ToFind As String) As Long

CountInstances = (Len(ToSearch) - _
Len(Replace$(ToSearch, ToFind, vbNullString))) _
\ Len(ToFind)

End Function

What this does is replace each occurrence of the character (or word or
expression) in the string with a null string (""). Assuming that the
character exists in the string, the length of the string will be reduced by
that operation. Knowing how much the length of the string decreased, we can
determine how many times the character occurred in the string.

If you're using Access 97 or earlier, you'll have to write your own
equivalent function to the Replace function. The downloadable database has
one such function in it.
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Sashafay" <af******@mwh.com> wrote in message
news:a1**************************@posting.google.c om...
Hi,

How I can count certain word in memo field?

For example I have 15 words in one field and "PLUMING" word repeats in
it 3 times. So I would like my code give me number three as the
answer.

Any help with it will be kindly,
Alex

Nov 13 '05 #2
Douglas J. Steele wrote:
Assuming you're using Access 2000 or newer, here's a nifty approach:

Private Function CountInstances( _
ByVal ToSearch As String, _
ByVal ToFind As String) As Long

CountInstances = (Len(ToSearch) - _
Len(Replace$(ToSearch, ToFind, vbNullString))) _
\ Len(ToFind)

End Function

What this does is replace each occurrence of the character (or word or
expression) in the string with a null string (""). Assuming that the
character exists in the string, the length of the string will be reduced by
that operation. Knowing how much the length of the string decreased, we can
determine how many times the character occurred in the string.
Very, very cool, Douglas.

If you're using Access 97 or earlier, you'll have to write your own
equivalent function to the Replace function. The downloadable database has
one such function in it.


Here's an A97 function.
Public Function CountInstances(ByVal ToSearch As String, _
ByVal ToFind As String) As Long

Dim intStart As Integer
Dim lngPos As Long

intStart = 1

Do While True

lngPos = InStr(Mid(ToSearch, intStart), ToFind)

If lngPos > 0 Then
CountInstances = CountInstances + 1
intStart = intStart + (lngPos - 1) + Len(ToFind)
Else
Exit Do
End If
Loop
End Function

ToSearch can be changed to a variant and then check if ToSearch is null
in case one is not sure each pass will contain a string.
Nov 13 '05 #3
Salad <oi*@vinegar.com> wrote in message news:<cQ*****************@newsread3.news.pas.earth link.net>...
Douglas J. Steele wrote:
Assuming you're using Access 2000 or newer, here's a nifty approach:

Private Function CountInstances( _
ByVal ToSearch As String, _
ByVal ToFind As String) As Long

CountInstances = (Len(ToSearch) - _
Len(Replace$(ToSearch, ToFind, vbNullString))) _
\ Len(ToFind)

End Function

What this does is replace each occurrence of the character (or word or
expression) in the string with a null string (""). Assuming that the
character exists in the string, the length of the string will be reduced by
that operation. Knowing how much the length of the string decreased, we can
determine how many times the character occurred in the string.


Very, very cool, Douglas.

If you're using Access 97 or earlier, you'll have to write your own
equivalent function to the Replace function. The downloadable database has
one such function in it.


Here's an A97 function.
Public Function CountInstances(ByVal ToSearch As String, _
ByVal ToFind As String) As Long

Dim intStart As Integer
Dim lngPos As Long

intStart = 1

Do While True

lngPos = InStr(Mid(ToSearch, intStart), ToFind)

If lngPos > 0 Then
CountInstances = CountInstances + 1
intStart = intStart + (lngPos - 1) + Len(ToFind)
Else
Exit Do
End If
Loop
End Function

ToSearch can be changed to a variant and then check if ToSearch is null
in case one is not sure each pass will contain a string.

Thanks guys!!!

Works just great and the way I want it to.

Alex
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

41
by: Ruby Tuesday | last post by:
Hi, I was wondering if expert can give me some lite to convert my word table into access database. Note: within each cell of my word table(s), some has multi-line data in it. In addition, there...
3
by: Laurie | last post by:
I am using Automation in Access 2003 to open a Word Document and fill in some values using bookmarks. It all works perfectly except for one section. I am filling in some values in a previously...
1
by: deejayquai | last post by:
Hi Does anyone know if it is possible to display a word count as and when a user is inputting text into a memo field on a form. The code I'm using below is fine when applied to the 'On Exit'...
1
by: Jako | last post by:
Hi guys... Well once again I'm in a dilemma. Currently I have a RTF2 object in Access that is linked to a memo field in a table, the reason for this is so that I can have bullets and numbers in...
8
by: ljungers | last post by:
Wondering if somone knows how to open a Access report in Word or export it to Word. Currently I'm opening and printing a report using VBA with the following command (DoCmd.OpenReport "TheReportName",...
1
by: rlntemp-gns | last post by:
Re: Access 2003/Word 2003 I have about 100 motivational documents that I am wanting to import into a small database and put a front end on it that would allow the user to select one, read it and...
3
by: csgraham74 | last post by:
Hi Guys, I was wondering if soemone could help me. Im trying to write a piece of code that queries a field in ms access for a keyword. what i want to do is count the number of times the...
5
by: Dean | last post by:
Hi, I have a table with non-unique identifiers. I need to take all the values with the same ID's and combine them into one field with a semicolon as a seperator. These values may exceed 255...
2
by: beanie | last post by:
i am a beginer in c programming and i am trying to Create a Concordance of Word Count for a Text File but my code is not working.pls can anyone helpme out.here is my code: #include <stdio.h>...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.