Hey guys,
I've got a module that breaks up a line of an address to separate city, state, and zip. It works great on single word cities like Denver or Atlanta, but with two or more words (Green Bay, West Palm Beach, etc) it bombs out. Can anyone take a peek and see how this could be adjusted? I'm at a loss. The code is basically looking for the first space in the string and cutting off the left-most section for the result, which is what I want, since the address is formatted as such. Here's what I've got:
Thanks!!
I've got a module that breaks up a line of an address to separate city, state, and zip. It works great on single word cities like Denver or Atlanta, but with two or more words (Green Bay, West Palm Beach, etc) it bombs out. Can anyone take a peek and see how this could be adjusted? I'm at a loss. The code is basically looking for the first space in the string and cutting off the left-most section for the result, which is what I want, since the address is formatted as such. Here's what I've got:
Code:
Sub GetAddSep()
Dim intPos As Integer
Dim FullAdd As String
Dim test As String
Dim Bcity As String, Bstate As String, Bzip As String
Dim strLeftPart As String
On Error GoTo Err_Command0_Click
'intPos = InStr(strName, " ")
'---Format Address---'
FullAdd = "SACRAMENTO CA 99999" 'a string like this works. Change Sacramento to SAN DIEGO or WEST PALM BEACH..epic fail.
test = Right(FullAdd, 10)
If Mid(test, 6, 1) = "-" Then
Bzip = Mid(test, 1, 5)
Else
Bzip = Right(FullAdd, 5)
End If
Bcity = Mid([FullAdd], 1, InStr([FullAdd], " ") - 1) 'works for single cities
strLeftPart = Mid([FullAdd], InStr([FullAdd], " ") + 2, Len([FullAdd]))
Bstate = Mid(Trim([test]), 1, InStr([test], " ") + 2)
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub
Thanks!!