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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need expression to take last word in text field 1

Status
Not open for further replies.

TeddB

MIS
Jul 16, 2001
38
US
Have a text field containing many words. Need only last word.

ex: mountain stream grass

Have tried RIGHT function, but can't supply 'lenght' number because the lenght of the word varies.

"A good man knows his limitations." -- "Dirty Harry" Callahan (Clint Eastwood)
 
Here is a Function that should be copied and pasted into a database Module. It searches a string from the right looking for a specifically designed string of characters which in this instance will be a space.

Public Function InStrRight(vSearchStr As String, vTargetStr As String, vStart As Long) As Long
Dim I As Integer
For I = vStart To 1 Step -1
If InStr(I, vSearchStr, vTargetStr, 1) = I Then
InStrRight = I 'Position of vTargetStr
Exit For
End If
Next I
End Function

Make you call to strip the right most word of a string with the following:

Trim(Mid$(<YourString>, InStrRight(<YourString>, &quot; &quot;, Len(<YourString>)))

Just update the Mid$ function with the name of either a form control, a field name, or a variable that is holding the long string of words.

Bob Scriver
 
in a2k
right(yourstring,len(yourstring)-instrrev(yourstring,&quot; &quot;))
 
Thanks Bob. Your function worked like a charm!

&quot;A good man knows his limitations.&quot; -- &quot;Dirty Harry&quot; Callahan (Clint Eastwood)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top