identify word in a string

DeanRowe

Registered User.
Local time
Today, 10:05
Joined
Jan 26, 2007
Messages
142
Hi,

Does anyone know how to identify a word in a string?

I have a field called "ImportCSV" which has upto 1000 characters.

i want to apply an if statement to the code of an event button on my form.

For example...

if "ImportCSV" contains the word "Goldmine" then
do this
else do this

I've tried lots of different things such as "like" and wildcards* but no luck.

Does anyone know how to do this?

The word could appear anywhere in the string.

Thank you for your time

Dean
 
Dean,

The first thing you need is a way to identify the word being searched! How is the program getting the input (i.e. - "Goldmine")???

Here's Bob's Reverse String function:

http://www.access-programmers.co.uk/forums/showthread.php?t=135710&highlight=reverse+string

You should use that method to search the entire string being inputted, in order from the first letter to the last letter (backwards, compared to Bob's example). All you have to do is extract the letters from the entire string, in sequential order, one at a time, and compare them to the sequential ordering of the letters of the input value. You might have to do it this because of what you said:
The word could appear anywhere in the string.
That's a pain to deal with!
 
You can use instr()
Code:
Dim result as integer

result = instr(importcsv,"goldmine")

if result > 0 then
  'String found do something
else
 'string not found, do something else
end if

Import csv is assumed to be a variable here, but it could be a recordset field, a textbox value etc

instr() as above returns the starting position in your first argument of the second string.

i.e. if Importcsv = "I found a goldmine"
result should be 11
 
Am I missing something here? Doesn't Instr do this?

Brian

Beaten to the punch again, I really must learn to type quicker.
 
beautiful! thank you very much indeed - cooking on gas again!!

thank you!!!
 

Users who are viewing this thread

Back
Top Bottom