Solved

separateing first and last names

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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 …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 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