Display certain words from a sentence

Nishikawa

Registered User.
Local time
Yesterday, 16:08
Joined
May 17, 2007
Messages
97
Hi,

I would like to know if it is possible to display a certain word within a sentence separated by commas. Eg: New York, new york, United States

I would like MS Access to show first words (New York) in one column and last words (United States) in another column. I am unable to use left or right function as the length of the words and the number of commas are unknown is very row.


Thanks
 
Nishi,

You're gonna have to use a Public Function for this:

Your query:

Code:
Select fnGetWords([YourField], "First") As FirstWord,
       fnGetWords([YourField], "Last")  As LastWord,
From   YourTable

In a Public module:

Code:
Public Function fnGetWords(TheString As String, WhichElement As String) As String

dim varArray as Variant
varArray = Split(TheString, ",")

If WhichElement = "First" Then
   fnGetWords = varArray(0)
Else
   fnGetWords = varArray(UBound(varArray))
End If

End Function

Wayne
 
Thanks man!! May I know how do you know all these functions? I would like to read more about it so that I do not have to keep bothering you guys for such simple problems. :)
 
Thanks man!! May I know how do you know all these functions? I would like to read more about it so that I do not have to keep bothering you guys for such simple problems. :)

It's called "experience" and also knowing how to search.

1. Use the VBA help file. It actually has a lot of great material there.

2. Use the search facility on this website. It really does work.

3. Use Google. Start by using the proper starting keywords like:

Microsoft Access VBA Whatever function

and you will see more than you've ever thought possible.
 
And I hope that the meaning of "Whatever Function" came through in that you substitute the name of the function you are interested in. :)
 
Indeed, just having a little fun... :D
 
Actually I think forums like this often give a more complete answer than you get from Google or Access Help.

Left() and Right() are a good example. From the forum you are far more likely to get the other vital parts such as InStr, Len and Trim.

I have often thought that a good addition to a forum would be a box/field where one of the posters on a thread could make an entry so as to make "search" much better.

As a side note it is quite interesting to check Who's On Line and look at the threads being viewed by Guest. Most of them way back in time.
 
Actually, you can find posts on the forums really quick and easy by using Google.
 
Actually, you can find posts on the forums really quick and easy by using Google.

I seem to remember Google was an option for Search on the forum but can't see it now......Friday afternoon:D

Bob, as an example what would you enter to search for something like this topic. Right or Left would get plenty if the search was on content of posting but a lot would be irrelevant.
 
actually, i thought waynes snippet was really impressive

i have tended to do stuff like this the hard way, reading strings a char at a time. it works, but ill try to remember waynes idea in the future ...

------------
now a similar example

if you have a string that you want to process a character at a time - say to add the ascii values of each char, or to change certain characters - is there an easy way of doing this

i am doing it by string slicing, a character at a time with mid function, and then reassembling the string, but it is very awkward in that mid(mystring,1) returns a string, which cant be handled in quite the same way as a char or byte (or can it?)
 

Users who are viewing this thread

Back
Top Bottom