Splitting address fields into 3 separate fields

S

Shirley

Hi,
I'm trying to create a function to split up Ciy, State,
and Zip data from one field to 3 fields.

Here's the code:
If commapos <> 0 Then
city = Trim(Left$(address, commapos - 1))
length = Len(address)
'state = Right$(address, length - commapos)
state = Trim(Mid$(address, InStr(address, ",") + 1, 4))
zip = Trim(Right$(address, 5))

This code works if the state is in one word,
like "Florida", but not "New York"

Any suggestions?

Thanks
 
J

John Spencer (MVP)

Assuming commapos is the position of a comma in the address string.


If commapos <>0 then
city = Trim(Left$(address, commapos - 1))
State = Mid(Address,commapos +1)
State = Trim(Left(State,Len(State)-5))
Zip = Trim(Right(Address,5))
End if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top