Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Splitting Hairs (Or Strings)

Status
Not open for further replies.

Dannybe2

Programmer
Jan 31, 2001
136
GB
To save time, I would have a name function which I have combined the firstname and lastname as follows:

=FirstName & " " & LastName

When a user selects a name based on this, I want to then split it back into FirstName and LastName fields again to prevent the user having to enter in two fields instead of one. How do I split it?
 
To split the string...

strName = FirstName & " " & LastName

FirstName would be
Code:
   Left(strName,instr(strName," ") - 1)
LastName would be
Code:
   Mid(strName,instr(strName," ") + 1)

However, you have to watch out for people with two first names that would contain a space. The Left and Mid statements offered will return everything to the left of the first space in the string and everything after the first space in the string, respectively.

I would think that if the names are indexed, it wouldn't be an issue. Where are you using the expression that puts them together? A query? form? report?


John

Use what you have,
Learn what you can,
Create what you need.
 
i agree--are the names held in a table? then you can just pull them from the table based on the index of the 'combined' name that the users chooses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top