Help with text function

T

Terrence Carroll

I need a function to help return the first name of a text sting that contains
last name,first name, midlle initial.

For instance for "Walker,Catrina L" I need to return "Catrina"
 
J

Jeff Boyce

Terrence

Are you absolutely, positively certain that EVERY text string contains the
sequence LastName, FirstName MiddleInitial?

Cher, for example, ...

.... or Jean Claude van Damm

.... or Billy Bob Thorton

If you can, without question, state that every text string has a single
comma in it, placed between the LastName and FirstName (hmmm, what about
John Doe, Jr. ... ??!? Doe, Jr., John), then you could use a query to find

* the string remaining after the comma, then
* that portion of that remainder that happens before the next space

You'd use the InStr(), Left(), Right(), Mid() functions in that query. You
might even need to do it in two steps, first to get the remainder, then to
isolate the FirstName.

Good Luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
K

Ken Snell

Public Function GetFirstName(strWholeName AS String) AS String
Dim strWorking As String
strWorking = Mid(strWholeName, InStr(strWholeName, ",") + 1)
strWorking = Left(strWorking, InStr(strWorking, " ") - 1)
GetFirstName = strWorking
End Function


The above code assumes that strWholeName passed to the function will never
have a NULL value, and that it always contains a comma and a space to the
right of the comma.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top