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

To Use "RTrim" Or "Mid" for Sting 1

Status
Not open for further replies.

WestView

Technical User
Jan 7, 2003
67
US
Hello All,

I have a single column field that contains both a name and an e-mail address:

Alice In Chains aichains@aol.com
Howdie Doodie hd@msn.com

I need a query that removes the e-mail address and leaves the name:

Alice In Chains
Howdie Doodie

Since the e-mail address is consistent - in that it has no spaces - I thought that would be the way to go using Mid(). But, I can’t get it right.

I would be grateful for any/all help or suggestions.

Thanks!!!

- Tom

 
Hi!

Try this:

Mid(YourField, InStrRev(Trim(YourField), " ") + 1)

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Oops, Jeff, I think you got it backwards - I think Tom wants to strip the email and leave the name. I think this is what you meant:
Code:
Left([YourField], InStrRev(Trim([YourField), " ") - 1)

Ken S.
 
wish i could test this but all i have is access97 and it doesn't have the InStrRev function

but hey, shouldn't the result of using InStrRev to find the first blank in the reverse direction actually be subtracted from the length of the field to come up with the second parameter for the LEFT function?

:)

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts July 10 2005)
 
rudy,

One would think so. It's a bit confusing, but InStrRev looks for the match string from the right, but returns the position where it is found from the left of the string. So in Westview's example "Howdie Doodie hd@msn.com" - InStrRev([MyField], " ") returns 14 - the first occurrence of the space character when looking from the right is at the 14th position from the left. So then we subtract 1 from that number to arrive at the number of characters to grab with the Left function.

I'm sure there's a workaround for Access 97 - let me fiddle with it and I'll see what I can come up with.

Ken S.
 
PHV, once again, right on the mark. Was just getting ready to post a bit of code, but the FAQ is much better.

Ken S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top