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

Splitting A Name Field Into Single Fields

Status
Not open for further replies.

iain2003

MIS
Jan 16, 2003
9
GB
Hi,

I used to have an inherited piece of code that would allow me to strip the salutation, first name and surname from a single name field regardless of the differing total characters. I have unfortunately lost this code and would very much like to split some records for a mail merge, any help would be much appreciated.

E.g. NameField
Mr J Bloggs

Sal Initial Surname
Mr J Bloggs

Thanks


 
OK, here's some code totally off the top of my head.
ChunkNumber is 1 based.

To get the first sub-field:
blah = GetSpaceDelimChunk(1, "This is a test")

function GetSpaceDelimChunk(ChunkNumber as integer, SourceText as string) as string
Dim PrevPos as integer
PrevPos = 1

dim done as integer
done = false

dim counter as integer
counter = 1
do while not done and counter <= ChunkNumber
dim SpacePos as integer
SpacePos = instr(PrevPos, SourceText, &quot; &quot;)
if SpacePos = 0 then
SpacePos = len(SourceText)
done = true
endif
if counter < ChunkNumber then PrevPos = SpacePos + 1
loop
if counter = ChunkNumber then
getspacedelimchunk = mid(sourcetext, prevpos, SpacePos - PrevPos)
endif
end function


Of course this function will need testing and fleshing out, but it's a start...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top