When things get this complicated I use regular expressions to do the
parsing. Even though they're difficult I find them less trouble than
writing huge amounts of painstaking code using VB's native string
functions.
For example (here's one I made earlier!), the regular expression below
will parse most addresses structured like these:
15 Broadway
12 Avenue Rd
660 North Avenue Suite 11
12345 North 35th St., Apt #99
into
Street Number if any
Street prefix (North|South|East|West) if any
Street name
Street type (e.g. Rd, Avenue) if any
Unit number if any
Here's the regex, or rather VBA to assemble it:
'Assemble regular expression to parse address
'Item 0: Optional street number at start of string
Regex = "^\s*(\d+\s+)?"
'Item 1: Optional North/South etc.
Regex = Regex & "(North|South|East|West)?"
'Item 2: Street Name (required)
Regex = Regex & "\s*(?
w+.*?)"
'Item 3: Optional Street Type (add more types to list if required)
Regex = Regex & "(?:\s+(Street|St\.?|Lane|Ln\.?|Boulevard|Bvd\.?|" _
& "Road|Rd\.?|Drive|Dve?\.?|Avenue|Ave?\.?|Way|Crescent|Cr\.?|" _
& "Terrace|Tce\.?|Alley|Place|Pl\.?|Square|Sq\.?))?)"
'Could add an element here to look for DC-style compass quadrants
'Item 4: Optional apartment number at end of string
Regex = Regex & ",?\s*?\w*?(?:\s+#?\s*(\d+))?\s*$"
One simple way to use regular expressions to parse data in Access is
with the rgxExtract() function at
http://www.j.nurick.dial.pipex.com/Code/vbRegex/rgxExtract.htm