G
Guest
I have copied and am attempting to use the following code from Allen Browne,
but for some reason it won't execute properly. I get the message that the
..Update in the code is incorrect. Can someone help me figure out what I have
done wrong? Thanks in advance.
Private Sub cmdbtnRepeat_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 "Select the record to duplicate."
Else
'Duplicate the main record: add to form's clone.
With Me.RecordsetClone
.AddNew
!ToDoID = Me.ToDoID
!ToDoCategory = Me.ToDoCategory
!ToDoAction = Me.ToDoAction
!Other = Me.Other
!ProgressNotes = Me.ProgressNotes
'etc for other fields.
.Update
'Save the primary key value, to use as the foreign key for the
related records.
.Bookmark = .LastModified
lngID = !ToDoID
'Display the new duplicate.
Me.Bookmark = .LastModified
End With
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdbtnRepeat_Click"
Resume Exit_Handler
End Sub
but for some reason it won't execute properly. I get the message that the
..Update in the code is incorrect. Can someone help me figure out what I have
done wrong? Thanks in advance.
Private Sub cmdbtnRepeat_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 "Select the record to duplicate."
Else
'Duplicate the main record: add to form's clone.
With Me.RecordsetClone
.AddNew
!ToDoID = Me.ToDoID
!ToDoCategory = Me.ToDoCategory
!ToDoAction = Me.ToDoAction
!Other = Me.Other
!ProgressNotes = Me.ProgressNotes
'etc for other fields.
.Update
'Save the primary key value, to use as the foreign key for the
related records.
.Bookmark = .LastModified
lngID = !ToDoID
'Display the new duplicate.
Me.Bookmark = .LastModified
End With
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdbtnRepeat_Click"
Resume Exit_Handler
End Sub