This was extremely helpful.
The error I'm receiving is "The changes you requested to the table were not
successful becasue they would create duplicate values in the index, primary
key, or relationship. Change the data in the field or fileds that contain
duplicate data, remove the index, or redefine the index to permit duplicate
entries and try again."
Below is the code altered from the web instructions: The three fields that
are part of .AddNew can have duplicates. One of the tables does have a
required number that is incremented when the form is opened as a default
value =Format(Date(),"yymmdd") & Format([txtRegistration Case Number],"000").
Private Sub cmdDupe_Click()
'On Error GoTo Err_Handler
'Purpose: Duplicate the main form record and related records in the
subform.
Dim strSql As String 'SQL statement.
Dim lngID As Long 'Primary key value of the new record.
'Save and edits first
If Me.Dirty Then
Me.Dirty = False
End If
'Make sure there is a record to duplicate.
If Me.NewRecord Then
MsgBox "Please Enter Information to Duplicate."
Else
'Duplicate the main record: add to form's clone.
With Me.RecordsetClone
.AddNew
![Claim Number] = Me.cboClaimNumber
!SpecialtyID = Me.cboSpecialty
![Date Received] = Now()
'etc for other fields.
.Update
'Save the primary key value, to use as the foreign key for the
related records.
.Bookmark = .LastModified
lngID = ![Claim Number]
'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'm guessing it has something to do with the lngID but need some guidance.