GISnunavut
Programmer
All:
My first time posting. I'm using DAO in MS Access 2003.
Here's the story...I have a table called Collection_Step_Two with 8 columns and 12546 records. I'm attempting to create another table "Collection_Step_Three" from all data in "Collection_Step_Two".
However, in the source table, the column "Last_Name" is complex. This column is String type data. This column has many types of string values - NULL, proper "lastnames" and the following type (delimited with "@"s and "%"):
lastname@firstname@organization@%lastname2@firstname2@organization2@
For example : Bertulli@Margaret@@%Woodman@D.@@
What I need help with is to get the code to accept Null string and populate the destination table, accept and populate single instance lastnames into the desination table(ie. "Smith"), and finally, use the 2 delimiters to split the strings into new records (%) and then split each new record into the lastname, first name and organization
columns respectively.
Here is the code
My first time posting. I'm using DAO in MS Access 2003.
Here's the story...I have a table called Collection_Step_Two with 8 columns and 12546 records. I'm attempting to create another table "Collection_Step_Three" from all data in "Collection_Step_Two".
However, in the source table, the column "Last_Name" is complex. This column is String type data. This column has many types of string values - NULL, proper "lastnames" and the following type (delimited with "@"s and "%"):
lastname@firstname@organization@%lastname2@firstname2@organization2@
For example : Bertulli@Margaret@@%Woodman@D.@@
What I need help with is to get the code to accept Null string and populate the destination table, accept and populate single instance lastnames into the desination table(ie. "Smith"), and finally, use the 2 delimiters to split the strings into new records (%) and then split each new record into the lastname, first name and organization
columns respectively.
Here is the code
Code:
Function LastName_Split()
Dim dbs As Database
Dim rst As DAO.Recordset
Dim strRst As String
Set dbs = CurrentDb
strRst = "SELECT Collection_Step_Two.Borden_Number, Collection_Step_Two.Collection_Event, Collection_Step_Two.Collection_Year, " & _
"Collection_Step_Two.Collection_Title, Collection_Step_Two.Permit_Number, Collection_Step_Two.Last_Name, " & _
"Collection_Step_Two.First_Name, Collection_Step_Two.Organization " & _
"FROM Collection_Step_Two"
Set rst = dbs.OpenRecordset(strRst)
Dim bn_temp As String
Dim collection_eventxxx As Long
Dim collection_yearxxx As String
Dim collection_titlexxx As String
Dim permit_numberxxx As String
Dim last_namexxx As String
Dim first_namexxx As String
Dim organizationxxx As String
Dim LastNameArray() As String
Dim LastNameArray2() As String
Dim intLoopCounter As Integer
rst.MoveFirst
Do Until rst.EOF
bn_temp = rst(0)
collection_eventxxx = rst(1)
collection_yearxxx = rst(2)
collection_titlexxx = rst(3)
permit_numberxxx = rst(4)
last_namexxx = rst(5)
first_namexxx = rst(6)
organizationxxx = rst(7)
LastNameArray() = Split(last_namexxx, "%")
For intLoopCounter = 0 To UBound(LastNameArray)
Dim intLoopCounter2 As Integer
LastNameArray2 = Split(LastNameArray(intLoopCounter), "@")
For intLoopCounter2 = 0 To UBound(LastNameArray2)
Dim rst2 As DAO.Recordset
Set rst2 = dbs.OpenRecordset("Collection_Step_Three", dbOpenDynaset)
With rst2
.AddNew
!Borden_Number = bn_temp
!collection_event = collection_eventxxx
!collection_year = collection_yearxxx
!collection_title = collection_titlexxx
!permit_number = permit_numberxxx
!permit_holder_id = intLoopCounter2 + 1
!last_name = LastNameArray2(0)
!first_name = LastNameArray2(1)
!organization = LastNameArray2(2)
.Update
rst2.Close
Set rst2 = Nothing
End With
Next intLoopCounter2
Next intLoopCounter
' bn_temp = ""
' collection_eventxxx = ""
' collection_yearxxx = ""
' information_temp = ""
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
MsgBox "Last Name Splitting Complete"
End Function