Solved

separateing first and last names

Posted on 1999-01-18
2
137 Views
Last Modified: 2010-05-03
I have a database field that consists of first and last names. I would like to retrieve the first name and the last name separately. Using VB4 16 bit, how would I go about retrieving first name and last name so I have two fields, first and last?
0
Comment
Question by:dtucker
2 Comments
 
LVL 1

Accepted Solution

by:
rondeauj earned 10 total points
ID: 1469287
is there a seperator char(i.e. ",") or a space?

if so you can use the instr() function to do this:

if you are looking for a "," do this

dim tempstring1,tempstring2 as string
dim x as integer

x = instr(dbfield, ",")
  if x <> 0 ' then a match was found
     tempstring1 = left$(dbfield,x)
     tempstring2 = right(dbfield,len(dbfield)-x)
  end if

dim tempstring3 as string
tempstring3 = tempstring1 & chr$(13) & chr$(10) & tempstring2
msgbox tempstring3
0
 
LVL 3

Expert Comment

by:traygreen
ID: 1469288
Several things to consider, but basically (assuming first <space>last)
iSpacePos = Instr(sCombinedName, " ")
if iSpacePos > 0 then
  FName = mid(sCombinedName, 1, iSapcePos)
  LName = mid(sCombinedName, iSpacePos + 1)
else
  FName = sCombinedName
endif

if Last name <comma> first name....

icommapos = instr(sCombinedName, ",")
if icommapos > 0 then
  LName = mid(sCombinedName, 1, iCommaPos)
  FName = mid(sCombinedName, iCommaPos + 1)
else
  LName = sCombinedName
end if

If you have another format, let me know what it is
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

707 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

11 Experts available now in Live!

Get 1:1 Help Now