Solved

separateing first and last names

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 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…

863 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

19 Experts available now in Live!

Get 1:1 Help Now