yog2go
Is this a one-time only conversion routine?
Is the account ID format on the non-normalized business location consistent? Is it always ", " (comma + space)
Is the Account ID always six characters long?
I would use a visual basic program...
Assumptions
OLD_tblBusinessLoc - original table
NEW_tblBusinessLoc - original table
BL - field name for business locations, numeric, long interger
AI - field name for AccountID. How this data type is stored will impact the logic in how to parse / strip off the account ID.
Your new table does not have an apparent primary key. Not important for this excercise, but something to consider.
I am going to use DAO for the read and write. You can also use ADO for the read/write or read-only and use SQL for the write.
I am going to go through the entire "old" table.
Code:
[COLOR=blue]Private Sub WalkBizLocations() [/color]
Dim dbs as DAO.Database, rstOld as DAO.RecordSet
Dim strAILong as String, lngBL as Long
Set dbs = CurrentDB()
set rstOld = dbs.Openrecordset("OLD_tblBusinessLoc")
'Very simple walk through the table
With rstOld
.MoveFirst
Do While Not .EOF
WriteNewLocation !BL, !AI
.MoveNext
Loop
End With
rstOld.Close
dbs.Close
Set rstOld = Nothing
Set dbs = Nothing
End Sub
[COLOR=blue]
Private Sub WriteNewLocation(lngBL As Long, strAILong As String)[/color]
Dim dbs As DAO.Database, rstNew As DAO.Recordset
Dim strAI As String, strSearch As String, intX As Integer
Set dbs = CurrentDb()
Set rstNew = dbs.OpenRecordset("NEW_tblBusinessLoc")
'Logic how the accounts are parsed or stripped off
'will be impacted by the AI string
strSearch = ", "
Do While Len(Nz(strAILong, ""))
intX = InStr(1, strAILong, strSearch)
If intX > 0 Then
strAI = Left(strAILong, intX - 1)
strAILong = Right(strAILong, Len(strAILong) - intX - 1)
Else
strAI = strAILong
strAILong = ""
End If
With rstNew
.AddNew
!bl = lngBL
!ai = strAI
.Update
End With
Loop
rstNew.Close
dbs.Close
Set rstNew = Nothing
Set dbs = Nothing
End Sub
I broke the code into two subroutines - more flexible in that you can call the
WriteNewLocation with just one record, or as in this case, while "walking through" a record set.
If the AI account was always six characters, the above Do While loop could be replaced with a more effecient For / Next loop.
I placed a ", " as the search string -- I am assuming your sample data is correct.
Richard