Okay, here is the code that links the person with their hobbies in the tblPerson_Hobby junction table:
Dim rsP As ADODB.Recordset
Dim rsH As ADODB.Recordset
Dim rsPH As ADODB.Recordset
Dim sSQLP As String
Dim sSQLH As String
Dim sSQLPH As String
Dim HobbyArray As Variant
Dim vHobby As Variant
Dim sHobby As String
Dim i As Integer
sSQLP = "SELECT * FROM tblPerson"
Set rsP = New ADODB.Recordset
rsP.Open sSQLP, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
sSQLPH = "SELECT * FROM tblPerson_Hobby"
Set rsPH = New ADODB.Recordset
rsPH.Open sSQLPH, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
rsP.MoveFirst
Do Until rsP.EOF
ReDim HobbyArray(0)
i = 0
vHobby = rsP("Hobbies")
HobbyArray = Split(vHobby, ", ")
Do Until i = UBound(HobbyArray) + 1
sHobby = HobbyArray(i)
sSQLH = "SELECT * FROM tblHobby WHERE [Hobby] = '" & sHobby & "'"
Set rsH = New ADODB.Recordset
rsH.Open sSQLH, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
rsPH.AddNew
rsPH("PersonID") = rsP("PersonID")
rsPH("HobbyID") = rsH("HobbyID")
rsPH.Update
rsH.Close
i = i + 1
Loop
rsP.MoveNext
Loop
rsP.Close
rsPH.Close
Since this is one-time prcessing, this overhead is okay.
All of the entries took this data:
PersonID LastName FirstName Email Hobbies
1 Smith John swimming, sailing, kayaking
2 Doe John hiking, camping
3 Jones John skydiving, crocheting
And added this data to the tblHobby:
HobbyID Hobby
36 camping
37 crocheting
38 hiking
39 kayaking
40 sailing
41 skydiving
42 swimming
And created these records in tblPerson_Hobby:
Person_HobbyID PersonID HobbyID
1 Smith swimming
2 Smith sailing
3 Smith kayaking
4 Doe hiking
5 Doe camping
6 Jones skydiving
7 Jones crocheting
Was that what you wanted?
mmcdonal
Look it up at:
http://wrox.books24x7.com