Return string using RIGHT function

B

Bird Byte

I have a field where a name was supposed to be entered as Last Name, First
Name. Now I have to separate out the first names (extracting the last names
was no problem). One problem is that some names were entered as last, first
and others were entered last,first - without a space.
The following worked with marginal results:

FName: Right([FullName],InStr([FullName],","))

Some results were fine, while others looked like this:
LName FName FullName
Dummdorfe rfe, Wayne Dummdorfe, Wayne
Nice opher Nice, Christopher
Hassles Charlie Hassles, Charlie

As you can see, some strings returned as wanted, while others didn't.
Any ideas how to get the correct string (entire first name with no comma or
leading space).

Thanks for any help!
 
B

Brendan Reynolds

Bird Byte said:
I have a field where a name was supposed to be entered as Last Name, First
Name. Now I have to separate out the first names (extracting the last
names
was no problem). One problem is that some names were entered as last,
first
and others were entered last,first - without a space.
The following worked with marginal results:

FName: Right([FullName],InStr([FullName],","))

Some results were fine, while others looked like this:
LName FName FullName
Dummdorfe rfe, Wayne Dummdorfe, Wayne
Nice opher Nice, Christopher
Hassles Charlie Hassles, Charlie

As you can see, some strings returned as wanted, while others didn't.
Any ideas how to get the correct string (entire first name with no comma
or
leading space).

Thanks for any help!


The Mid$() function will give you everything after the comma, and then you
can use the Trim() function to strip off any leading space. Here's an
example I tested in the Immediate window ...

? Trim(Mid$("some, text", InStr(1, "some, text", ",") + 1))
text
 
D

Douglas J. Steele

Right wasn't the right function to use.

To get what's after the comma, use

FName: Mid([FullName],InStr([FullName],",") + 2)

or

FName: Trim(Mid([FullName],InStr([FullName],",") + 1))

To get what's before the comma, use

LName: Left([FullName],InStr([FullName],",") - 2)
 
B

Bird Byte

Thanks for the ideas! This approach omitted the first letter when there was
no space after the comma. Brendan Reynolds' solution (using mid and instr
functions then trimming) worked like a charm.
Thanks very much!

KARL DEWEY said:
Try this --
FName: Right([FullName],Len([FullName])-(InStr([FullName],",")+1))

--
KARL DEWEY
Build a little - Test a little


Bird Byte said:
I have a field where a name was supposed to be entered as Last Name, First
Name. Now I have to separate out the first names (extracting the last names
was no problem). One problem is that some names were entered as last, first
and others were entered last,first - without a space.
The following worked with marginal results:

FName: Right([FullName],InStr([FullName],","))

Some results were fine, while others looked like this:
LName FName FullName
Dummdorfe rfe, Wayne Dummdorfe, Wayne
Nice opher Nice, Christopher
Hassles Charlie Hassles, Charlie

As you can see, some strings returned as wanted, while others didn't.
Any ideas how to get the correct string (entire first name with no comma or
leading space).

Thanks for any help!
 

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