I am trying to transfer data from one database to another using adodb recordsets, the destinations tables are virtually the same in structure. I want to be able to transfer the information on the condition that the primary key does not exist in the destination table otherwise this create an error. Ths is the code I have been using so far but its been crashing because it attempts to add an existing primary key to the table. OutwardsRefNumber is the primary key column
Code:
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM Outwards", conOutwards, adOpenKeyset, adLockOptimistic, adCmdText
rs.MoveFirst
While Not rs.EOF
Set rst = New ADODB.Recordset
rst.Open "SELECT * FROM OutwardsWeekly", conCBSWT, adOpenKeyset, adLockOptimistic, adCmdText
rst.MoveFirst
While Not rst.EOF
If (rs!OutwardsRefNumber <> rst!OutwardsRefNumber) Then
rst.AddNew
rst!OutwardsRefNumber = rs!OutwardsRefNumber
rst!other9 = rs!other9
rst!other10 = rs!other10
rst!Mode = rs!Mode
rst.Update
End If
rst.MoveNext
Wend
rs.MoveNext
Wend