Splitting Text Fields

  • Thread starter Thread starter Hank Westscott
  • Start date Start date
H

Hank Westscott

I have a field that contacts two words separated by a ",".
How can I separate "Westscott, Hank" into two
fields "Westscott" and "Hank" since all the names are of
different lengths?
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If using Access 2000 & greater use the Split() function:

Dim a() As string

a = Split(Variable, ",")

a(1) will have "Westcott"
a(2) will have " Hank"

MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQBg4qIechKqOuFEgEQKP1QCghRzsGm89ankoPB4H/Ev4Nc4O2AoAoK3E
Vm3gRzeexY/UY3uEVfqn44nD
=J6pB
-----END PGP SIGNATURE-----
 
Just a minor point of clarification as the first item is
returned as array (0)...
a(0) will have "Westcott"
a(1) will have " Hank"

and if you have the original data as "Westcott, Hank,
Wayne"

a(2) will return " Wayne"

OK?
CJ
 
I have a field that contacts two words separated by a ",".
How can I separate "Westscott, Hank" into two
fields "Westscott" and "Hank" since all the names are of
different lengths?

You can use the Instr() function to find the position of the comma,
and then the Left() and Mid() functions to extract substrings:

LastName: Left([namefield], InStr([namefield], ",") - 1)
FirstName: Trim(Mid([namefield], InStr([namefield], ",") + 1))
 
Back
Top