If I understand right, TABLE Registration is not populated.
I called the old table (AutoNumber - Name - OldActivityNumber - OldActivityName) "OldTable"
Here is the VBA I used to populate the Registration table:
Code:
Public Sub UpdateActivity()
Dim D As DAO.Database
Dim O As DAO.Recordset 'OLD name TABLE
Dim L As DAO.Recordset ' New ACTIVITY TABLE
Dim P As DAO.Recordset ' New PERSON TABLE
Dim sSQL As String
Dim OldNum As String
Dim sPersonName As String
Dim k As Long
Set D = CurrentDb
'open recordset to be modified (source)
'- Name -
Set O = D.OpenRecordset("SELECT PersonName , OldActivityNumber FROM OldTable ORDER BY AutoNumber;")
' Open recordset on TABLE Activity
Set L = D.OpenRecordset("SELECT NewActivityNumber, OldActivityNumber FROM Activity ORDER BY OldActivityNumber;")
' Open recordset on New Person table
Set P = D.OpenRecordset("SELECT ID, TheName FROM Person ORDER BY ID;")
If Not O.BOF And Not O.EOF Then
O.MoveFirst
'counter
k = 0
Do Until O.EOF
OldNum = "OldActivityNumber = " & O.Fields("OldActivityNumber")
'Function ConvertQuotesSingle() handles names like O'Neil
sPersonName = "TheName = '" & ConvertQuotesSingle(O.Fields("PersonName")) & "'"
' find OldActivityNumber to get NewActivityNumber
L.FindFirst OldNum
' find PersonName to get New ID Number
P.FindFirst sPersonName
If L.NoMatch Or P.NoMatch Then
'
' You should add Error message here
' because ActivityID or Name was not found
' use msgbox or write Actto file to handle later
'
Else
k = k + 1
sSQL = "INSERT INTO Registration ( PersonID, ActivityID ) VALUES (" & P.Fields("ID") & ", " & L.Fields("NewActivityNumber") & ");"
D.Execute sSQL, dbFailOnError
End If
O.MoveNext
Loop
End If
MsgBox "Done.... Updated " & k & " records"
O.Close
L.Close
P.Close
Set P = Nothing
Set L = Nothing
Set O = Nothing
Set D = Nothing
End Sub
Code:
'converts a single quote to two single quotes
Function ConvertQuotesSingle(InputVal)
ConvertQuotesSingle = Replace(InputVal, "'", "''")
End Function
BTW, "Name" is a reserved word in Access and should not be used for object names....