Solved

Selecting Part of a field

Posted on 2008-06-23
6
200 Views
Last Modified: 2010-03-20
I swear I will get this down eventually!

I need to select only part of a User Name field.  Some of the User names have a middle initial at the very end of the string that I need to remove.

I need to convert:

smith, john a to
smith, john

Thanks!
0
Comment
Question by:mattturley
6 Comments
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Try this:

Mid("smith, john a",1,InStrRev("smith, john a"," ")))

returns smith, john

mx

0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Generic:

Mid(FullName,1,InStrRev(FullName"," "))

mx
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Opps .... extra ""

Mid([FullName],1,InStrRev([FullName]," "))


Query:

SELECT Mid([FullName],1,InStrRev([FullName]," ")) AS Expr1
FROM Table1;

mx
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:mattturley
Comment Utility
Not every record has a middle initial - when this is the case, the above gets rid of the first name.
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility

SELECT IIf(InStr([NameField]," ")<>InStrRev([NameField]," "),Left([NameField],InStrRev([NameField]," ")-1),[NameField]) AS Expr1
FROM Table1;
0
 
LVL 44

Expert Comment

by:GRayL
Comment Utility
As you can get what you want via a query, I recommend you leave your data intact.  Run this query:

SELECT IIF(instr(mytest," ") = instrrev(mytest," "), mytest, Left(mytest,instr(instr(mytest,", ")+2,mytest," "))) AS JustName FROM myTable;
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now