One Field splits to four fields

L

learning_codes

Hi,

I need your help to create how to split the words into four fields.


one field: Address, City State Zipcode

change to:

FieldA : Address
FieldB: City
FieldC: State
FieldD: ZipCode

your help would be much appreciated.
Thanks
 
T

Tony Toews

I need your help to create how to split the words into four fields.


one field: Address, City State Zipcode

change to:

FieldA : Address
FieldB: City
FieldC: State
FieldD: ZipCode

your help would be much appreciated.

The code is to start from the right and work your way left looking for
either a space or a comma. Using len and mid functions.

But you also need to understand that your data may be wrong. Folks
may not have put in a zip code or maybe the zip code is a nine digit
with a space in the middle. Or the state might be Miss rather than
MS. The comma may be missing or it may be another character.

So all those anomolies will need to be reviewed and corrected and then
you rerun your logic. Also if data is missing you might want to put
in dummy values so your logic works best. For example Address, City,
ZZ, and/ior 99999 for zip zode. Then you can get the users to go back
later with a query and attempt to fix the data.

Also this might be be best handled using a recordset given the
complexity of the string manipulation you will need to do. See the
Sample Code illustrating looping through a DAO recordset page at the
Access Email FAQ at
http://www.granite.ab.ca/access/email/recordsetloop.htm

Tony
 
J

John W. Vinson

Hi,

I need your help to create how to split the words into four fields.


one field: Address, City State Zipcode

change to:

FieldA : Address
FieldB: City
FieldC: State
FieldD: ZipCode

your help would be much appreciated.
Thanks

This can be a MAJOR pain. As Tony says, people won't have been consistant.
Looking for blanks in field values is fraught with problems:

"Salt Lake City Utah" (second blank)
"Fargo North Dakota" (first blank)
"St. Paul Minnesota" (second blank)
"Couer d'Alene ID" (second blank)
"Raleigh North Carolina" (first blank)

In addition, there's very likely to be lots of records with a comma between
the city and state, instead of or in addition to the comma before the city. If
you have any Canadian entries, you'll also have postcodes which may have
blanks in them: K1A 0B1 for example.

There will be a *lot* of manual cleanup required... good luck!
 
D

David W. Fenton

There will be a *lot* of manual cleanup required... good luck!

I would suggest that regularizing the data first would probably be
the best approach. For instance, replace " North Dakota" with ",
ND", and so forth (as well as all variations). If that leads to a
double comma, you easily run an update to replace ",," with ",".

This is fussy work, but I think it's better to do it in a single
field than it is to have to move stuff around manually between
different fields.

Another thing to consider is that you might find it useful to write
code that can use the Split() function to store the value in an
array, using, say " " as a delimiter. Then you could walk from the
end of the array examining what's in each item and acting
accordingly, then placing that in the appropriate field. You could
do something like taking the last item in the array, stripping out
"-" and then testing IsNumeric(). If that's true, then it's very
likely a zip code (heaven help you if there's Canadian records --
then you'd have to check if it alternated letters and digits).

Once you've processed out the zip code, then you can see if the next
item in the array matches a table of state names/abbreviations. If
so, you can put that in the state field.

If it's not, you'd check to see if combining that value and the
previous value with a " " in between matches your lookup table.

Once you've got a match, you'd then move to the next part, and if
you're lucky, you can process it against a zip code table and use
your already derived zip code to intelligently figure out what the
possibilities for the city name are.

Once you've parsed all of that, the remainder should, in theory, be
the address.

Coding this could be very difficult, and depends on having good
lookup tables. But if you need to do this for a large amount of
data, that's likely how I'd approach it.

Another alternative is to go back to the original source and ask if
you can get the data in a proper format!
 
Joined
Jun 21, 2010
Messages
3
Reaction score
0
Apologies for hijacking, but what would the code be, to split the data at every comma into a new field?
 

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