Solved

separateing first and last names

Posted on 1999-01-18
2
141 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…

749 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