Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 1 / December 2006

Tip: Looking for answers? Try searching our database.

separating a string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
janetager@yahoo.com - 24 Dec 2006 18:22 GMT
I have a field that has names in it in the format "last name, first
name".  I want code that will split this field for me at the comma so I
can make 2 separate fields for last name and first name.  Thanks.
Rick Brandt - 24 Dec 2006 18:27 GMT
> I have a field that has names in it in the format "last name, first
> name".  I want code that will split this field for me at the comma so
> I can make 2 separate fields for last name and first name.  Thanks.

FirstName: Mid([FieldName], InStr(1, [FieldName], ", ")+2)

LastName: Left([FieldName], InStr(1, [FieldName], ", ")-1)

Signature

Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt   at   Hunter   dot   com

Jeff Smith - 24 Dec 2006 19:34 GMT
Just incase some records don't have a space
LastName = Left([FieldName], Instr([FieldName], ",")-1)
FirstName = Trim(Mid([FieldName], Instr([FieldName], ",")+1))

>I have a field that has names in it in the format "last name, first
> name".  I want code that will split this field for me at the comma so I
> can make 2 separate fields for last name and first name.  Thanks.
Keith Hutchison - 24 Dec 2006 21:12 GMT
> I have a field that has names in it in the format "last name, first
> name".  I want code that will split this field for me at the comma so I
> can make 2 separate fields for last name and first name.  Thanks.

dim data as string
dim fields() as string
dim last as string
dim first as string

data = "Last name, first name"
fields = split( data, ",")
last = trim( fields(0) )
if ubound( fields ) > 0 then
  first = trim(fields(1))
end if

Cheers

Keith
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.