I'm trying to add records to an exisiting table called "Topics" (section as of "For Each SelectedTopic In SelectedTopicsC tl.ItemsSelecte d" in the code below). When executing the code i always get "Run-time error '3022': The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship". So it goes wrong at the creation of the Autonumber in the field "ID" (= the only field that is indexed - no duplicates). When debugging, line "TopicRecord.Up date" in the code below is highlighted. I have read several posts on this topic on this forum and on other forums but still cannot get this to work - i must be overlooking something....
Code:
Private Sub Copy_Click() Dim SelectedTopic As Variant Dim JournalEntryToCopyFromCtl, JournalEntryToCopyToCtl, JournalEntryDateCreatedCtl, SelectedTopicsCtl As Control Dim TopicRecord As Recordset Dim Counter As Integer Set TopicRecord = CurrentDb.OpenRecordset("Topics", dbOpenDynaset, dbSeeChanges) For Each SelectedTopic In SelectedTopicsCtl.ItemsSelected TopicRecord.AddNew For Counter = 3 To SelectedTopicsCtl.ColumnCount - 1 TopicRecord.Fields(Counter) = SelectedTopicsCtl.Column(Counter, SelectedTopic) Next Counter TopicRecord.Fields("JournalEntryID") = JournalEntryToCopyToCtl.Value TopicRecord.Fields("DateCreated") = JournalEntryDateCreatedCtl.Value TopicRecord.Update Next SelectedTopic TopicRecord.Close Set TopicRecord = Nothing End Sub
Comment