473,387 Members | 1,515 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,387 software developers and data experts.

find a word using txtcriteria and count the number of matching criteria

hello i need help in(

query criteria do count the number of matching search

i use ( Like "*" & [txtcriteria] & "*") but when i have 2 matching search in one record the count is 1

example text : the good the bad the ugly

if i search for "the" the count is one but i have 3
hope the idea is clear)

what im looking is the count of the matching txtcriteria


i found countif in excel and its work ,what about access how i can solve this problem plz help
Attached Images
File Type: jpg count1.jpg (24.6 KB, 97 views)
File Type: jpg count2.jpg (28.3 KB, 120 views)
Nov 21 '14 #1
5 999
jforbes
1,107 Expert 1GB
A Like statement is used to determine if a Row is to be returned as part of a RecordSet for a SQL Select. So it is working as it should to let you know that the Row has the word you are looking for.

What you'll need to do for each Row it to perform a Count on the particular Field. There is no native way to do that, that I know of, so you will have to resort to programming. This function will give you the Count:
Expand|Select|Wrap|Line Numbers
  1. Public Function getWordCount(ByRef sSentence As String, ByRef sWord As String) As Integer
  2.     Dim RegEx As Object
  3.     Dim regexMatches As Object
  4.     Dim oReturn As Variant
  5.  
  6.     Set RegEx = CreateObject("VBScript.RegExp")
  7.     RegEx.MultiLine = False
  8.     RegEx.Global = True
  9.     RegEx.IgnoreCase = False
  10.  
  11.     RegEx.Pattern = "[" & sWord & "]+"
  12.     Set regexMatches = RegEx.Execute(sSentence)
  13.  
  14.     getWordCount = regexMatches.Count
  15. End Function
You can then include the function as part of your query, like:
Expand|Select|Wrap|Line Numbers
  1. SELECT Books.Title, getWordCount([Books]![Title],[Forms]![Form2]![txtCriteria]) AS WordCount
  2. FROM Books;
Nov 21 '14 #2
its work but incorrect answer:for the word "the"

Title WordCount
the good the bad the ugly 3
the beauty and the beast 6
the rock 1
superman 1
Nov 21 '14 #3
jforbes
1,107 Expert 1GB
Hmm, It looks like your copy and paste got some extra characters in there? Maybe try to remove the " " out of the code?
Nov 21 '14 #4
yes right i did remove the " " out of the code ,actualy runing your code in vba (immediate window) work good and nice but when i use this code with query give me wrrong answer

plz see attach pic
Attached Images
File Type: jpg count3.jpg (21.6 KB, 82 views)
Nov 22 '14 #5
Actualy if someone interest this is the right code . anyway thanx jforbes for your try


Expand|Select|Wrap|Line Numbers
  1. Function CountSubstring(strInput As String, strSearch As String) As Integer
  2. While InStr(strInput, strSearch) > 0
  3.     strInput = Mid(strInput, InStr(strInput, strSearch) + Len(strSearch) + 1)
  4.     CountSubstring = CountSubstring + 1
  5. Wend
  6. End Function
Nov 23 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: DataFreakFromUtah | last post by:
Hello! No question here, just a procedure for the archive. Search critera: count records imported count data imported count number of rows imported count number of records imported record import...
0
by: Tommy | last post by:
Hello! Does anybody know how to insert text into bookmarks in Word using late binding? If I use early binding everything works fine. What I want to implement is somthing like this: for (int i...
11
by: Mack | last post by:
Hi all, I want to write a program to count number of bits set in a number. The condition is we should not loop through each bit to find whether its set or not. Thanks in advance, -Mukesh
0
by: abhilash12 | last post by:
is there any searchengine using with java for find word in ms word file pls help me
2
by: mfaisalwarraich | last post by:
Hi Everybody, I am using the following code to get the recordset of an external database. Dim dbPatients As Database Dim rsCountPatients As Recordset ' to count number of...
5
by: jambonjamasb | last post by:
I am wanting to create a report that summarises the number of items within a date range. For example I have a FIELD called System_Change. This is a drop down COMBOBOX that uses words like unix,...
1
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent...
0
by: saravanakumar muthurangan | last post by:
Hello all, i need to correct a misspelled word automatically with a most matching word by using MS word.dll in vb.net 2005, i m getting the checkspelling window with the below code but...
2
by: raknunna | last post by:
Hi, Please provide a query to find "count(*number) of grants in a role. we have a role ALPHA_ROLE and I just want count of only select grants existing in the role. Can someone help. Thanks in...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.