I've read a few things about how to copy records and mostly what I see is that copying doesn't work cause of the primary key being unable to be duplicated. However, I found this thread;
https://www.accessforums.net/access/...ord-15269.html
Where the individual managed to get a copy working using this example;
http://www.allenbrowne.com/ser-57.html
I'm getting the same error she got at the end where it says "Item not found in this collection". Please note that I am trying to copy the current record in my form.
So I think the important bit about my database is that my primary key is not automatic, it's a user designated number. The number is basically a series of numbers representing the date in a field called cboStartDate (for example: 240823 where 24 is the Japanese year, 08 is the month, and 23 is the day) and then two digit iterations up for how many records start on that date (example: 24082301, 24082302, 24082303.) Optimally, I would like to be specifying the number via a message box at the time of copy if automating that part isn't easy. Is this workable?
Here is the code I am using;
Code:
Private Sub CopyJob_Click()
'On Error GoTo Err_Handler
'Purpose: Duplicate the current form record
'Save any edits first
If Me.Dirty Then
Me.Dirty = False
End If
'Make sure there is a record to duplicate.
If Me.NewRecord Then
MsgBox "Select the record to duplicate."
Else
'Duplicate the main record: add to form's clone.
With Me.RecordsetClone
.AddNew
'This is my record's primary key. This part doesn't snag.
!JobOrderID = Me.JobOrderID.Value + 1
'This is an alphanumeric field on my form and where the code stops working.
!Combo351 = Me.Combo351
!SubName = Me.SubName
!JobOrderDate = Date
!cboStartDate = Me.cboStartDate
!Combo312 = Me.Combo312
!Check509 = Me.Check509
!Check529 = Me.Check529
!cboEndDate = Me.cboEndDate
!InstructorName = Me.InstructorName
!Eva1Due = Me.Eva1Due
!Eva2Due = Me.Eva2Due
!Eva3Due = Me.Eva3Due
!EvaluationNotes = Me.EvaluationNotes
!IntrRate = Me.IntrRate
!MonStart1 = Me.MonStart1
!MonFinish1 = Me.MonFinish1
!TueStart1 = Me.TueStart1
!TueFinish1 = Me.TueFinish1
!WedStart1 = Me.WedStart1
!WedFinish1 = Me.WedFinish1
!ThuStart1 = Me.ThuStart1
!ThuFinish1 = Me.ThuFinish1
!FriStart1 = Me.FriStart1
!FriFinish1 = Me.FriFinish1
!SatStart1 = Me.SatStart1
!SatFinish1 = Me.SatFinish1
!SunStart1 = Me.SunStart1
!SunFinish1 = Me.SunFinish1
'etc for other fields.
.Update
'Save the primary key value, to use as the foreign key for the related records.
.Bookmark = .LastModified
'Display the new duplicate.
Me.Bookmark = .LastModified
End With
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdDupe_Click"
Resume Exit_Handler
End Sub
I do not have any subforms on this form, so I removed the append query. I hope that didn't mess something up.
I'm grateful for any help!