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

How to return the last word in a string

Hi
My Employees table contains staffs' full names as it is an import from the HR system and I don't have control over the format.
Many of our staff have names 4, 5 or even 6 words long. I wish to use a combobox based on a query that is based on the Employees table that allows me to sort on the last name.
Currently the Names field consists of first_name second-fourth_names last_name
eg Jane Elizabeth Francis Jones
John Doe
Abdullah Mohammed Ouzi Nasser Shaban

I have found a query function
LastName: IIf(InStr(InStr([Name]," ")+1,[Name]," ")<>0,Right([Name],Len([Name])-InStr(InStr([Name]," ")+1,[Name]," ")),Right([Name],Len([Name])-InStr([Name]," ")))

Unfortunately in the example above it returns
Francis Jones, not Jones
Doe
Ouzi Nasser Shaban, not Shaban

My skills are limited and I don't know how to edit this function to parse right to the end of the string and pick up the last name only.

Can somebody please help.

Thanks
Dec 7 '07 #1
2 16182
FishVal
2,653 Expert 2GB
Hi, sfindlay.

Try one of this:
Expand|Select|Wrap|Line Numbers
  1. Mid([Name], InStrRev([Name], " ") + 1)
  2. Split([Name], " ")(UBound(Split([Name], " ")))
  3.  
The first is expected to be faster.

Regards,
Fish
Dec 7 '07 #2
NeoPa
32,556 Expert Mod 16PB
Nice one Fish. Another one to add to those I was ignorant of :)

SFindlay, You need to replace your line with :
Expand|Select|Wrap|Line Numbers
  1. LastName: Mid([Name], InStrRev([Name], " ") + 1)
Let us know what this gives you :)
Dec 13 '07 #3

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

Similar topics

1
by: Dustin D. | last post by:
If I attempt to crop a string using regular expressions and the () operator for grouping, Perl always seems to return the last match. For instance, if I have the following: my $test =...
6
by: Bimo Remus | last post by:
Hi, I am currently taking a C++ class and am having problems with a homework assignment. My problem is that I need to pull the first and last words out of of a character string array which is in...
0
by: Mike | last post by:
Hello All, I wrote a function that will create a file system directory for my web application and display it in the IE Treeview control. Everything wrotes great! What I'm having trouble with is...
9
by: Steve | last post by:
Hello (and a happy new year) I'm quite new to C++ and have to programm something for school and can't get my head around a couple of things, but at the moment this one is the most important for...
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
9
by: Steven | last post by:
Hello, I have a question about strcmp(). I have four words, who need to be compared if it were two strings. I tried adding the comparison values like '(strcmp(w1, w2) + strcmp(w3, w4))', where...
19
by: Chantelle | last post by:
I've got this A2K DB that has a continuous form that lists Suppliers and their details. The form has a field for each supplier that holds several Keywords that reflect the suppliers products or...
4
by: whitej77777 | last post by:
I am trying to write a user defined function that will allow me to strip off the last carriage return and line feed from a text field. We have address fields stored in a text field for our ERP...
3
by: madhurchadha | last post by:
how do i remove the last word from a string in c# suppose string is "hi how are you" i wanna remove you
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: 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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.