?
Solved

separateing first and last names

Posted on 1999-01-18
2
Medium Priority
?
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
rondeauj earned 30 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

741 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