I am trying to write an update query that will split apart an address field into two or three parts: StreetNumber, Street, and ApartmentNumber [if there is an apartment number].
The following query works fine to split out the Street Number:
UPDATE Workers SET Workers.StreetNumber = Mid([Full Address],1,InStr([Full Address]," ")-1)
WHERE (((Workers.StreetNumber) Is Null) AND ((Mid([Full Address],1,1)) In ("1","2","3","4","5","6","7","8","9")));
And the following query gives everything after the street number [ie, street name and apartment number, if there is one]
UPDATE Workers SET Workers.Street = Mid([Full Address],InStr([Full Address]," ")+1)
WHERE (((Workers.Street) Is Null) AND ((Mid([Full Address],1,1)) In ("1","2","3","4","5","6","7","8","9")));
However, I can't figure out how to get the second query to return ONLY the street information [excluding the apartment number if there is one], and I haven't been able to write a third query to split off the apartment number. Because the apartment number is almost always preceded by the # sign, [and I am willing to hunt for the ones that aren't and change them by hand], I thought I could use the # as criteria to identify which records to update using the third query, and to mark the place where the string should be split. But I can't get it to work.
Any suggestions?
The following query works fine to split out the Street Number:
UPDATE Workers SET Workers.StreetNumber = Mid([Full Address],1,InStr([Full Address]," ")-1)
WHERE (((Workers.StreetNumber) Is Null) AND ((Mid([Full Address],1,1)) In ("1","2","3","4","5","6","7","8","9")));
And the following query gives everything after the street number [ie, street name and apartment number, if there is one]
UPDATE Workers SET Workers.Street = Mid([Full Address],InStr([Full Address]," ")+1)
WHERE (((Workers.Street) Is Null) AND ((Mid([Full Address],1,1)) In ("1","2","3","4","5","6","7","8","9")));
However, I can't figure out how to get the second query to return ONLY the street information [excluding the apartment number if there is one], and I haven't been able to write a third query to split off the apartment number. Because the apartment number is almost always preceded by the # sign, [and I am willing to hunt for the ones that aren't and change them by hand], I thought I could use the # as criteria to identify which records to update using the third query, and to mark the place where the string should be split. But I can't get it to work.
Any suggestions?