Thanks Fred
No ".'s" in any of the names. While I recognize the commands I am not sure I could have ever gotten them put together this way. I will use this opportunity to review how it works and should learn several things.
I really didn't have a choice in the delimiter as it is an output from another program. Now however it looks like I can automate all of the Access process and most of the external process.
I really appreciate the time it took you to do the attached
Thanks again
Harr
----- fredg wrote: ----
rkc, fredg Sorry.... "It" refers to the query. I have not bee
able to get the query to recoginize when the location is missin
(which is expected in some cases). The results have been th
district ends up in the location field and the company ends up i
the district field and the company field is blank for distric
sites which have no location instead of the location field bein
blank.
always a district and company. Example we have district location
like Chicago.company (xxxxxx.xxxxxx) and each district also ha
locations like Peoria.Chicago.company (xxxxxx.xxxxxx.xxxxx) As yo
can see by the examples the location and districts are both cit
names so having a location for a district is redundant. Th
information was extracted from an LDAP directory service. Thes
are the only 2 variations.
location is missing and fill in only the district and >compan
fields (ex. 1) instead it fills in the location and distric
fields.
when there are two periods you have all three fields and when yo
have one it is district and company.
The below will parse the data you have given, PROVIDED THERE IS N
LOCATON, CITY, OR COMPANY WITH A PERIOD IN THE NAME i.e. St. Louis
St. Petersburg, St. Paul, etc.
The period is NOT a good column delimiter.
It would be better to use the "|".
Here are 3 functions that will separate your example into 3 differen
fields, in a query, using Access 2000 or later. It presupposes tha
any missing data will ALWAYS be the location.
Here is the query SQL:
SELECT YourTable.CombinedNames, ParseLocation([CombinedNames]) A
Location, ParseCity([CombinedNames]) AS City
ParseCompany([CombinedNames]) AS Company FROM YourTable WHER
(((YourTable.CombinedNames) Is Not Null));
Change the above table and Field names as needed
In a module, paste the following 3 functions.
Public Function ParseLocation(FieldIn
Dim intX As Intege
Dim intY As Intege
Dim intZ As Intege
Dim Location As Strin
intX = InStr(1, FieldIn, "."
Do While intX <>
intZ = int
intY = intY +
intX = InStr(intX + 1, FieldIn, "."
Loo
If intY = 1 The
Location = "Not Given
Else
Location = Left(FieldIn, InStr(1, FieldIn, ".") - 1)
End If
ParseLocation = Location
End Function
====================
Public Function ParseCity(FieldIn)
Dim intX As Integer
Dim intY As Integer
Dim intZ As Integer
Dim City As String
intX = InStr(1, FieldIn, ".")
Do While intX <> 0
intZ = intX
intY = intY + 1
intX = InStr(intX + 1, FieldIn, ".")
Loop
If intY = 2 Then
City = Mid(FieldIn, InStr(1, FieldIn, ".") + 1, (intZ - 1) -
InStr(1, FieldIn, "."))
Else
intX = InStr(1, FieldIn, ".")
City = Left(FieldIn, intX - 1)
End If
ParseCity = City
End Function
==============
Public Function ParseCompany(FieldIn)
ParseCompany = Mid(FieldIn, InStrRev(FieldIn, ".") + 1)
End Function
=============
You can change
Location = "Not Given"
to
Location = ""
if you simply want to leave it blank.