Duplicate Record Error

hi there

Registered User.
Local time
, 22:37
Joined
Sep 5, 2002
Messages
171
hi everyone,

i have a form that i'm trying to create a button to duplicate the record. i'm using the control wizard which produces the following code:

Private Sub DuplicateRecord_Click()
On Error GoTo Err_DuplicateRecord_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70

Exit_DuplicateRecord_Click:
Exit Sub

Err_DuplicateRecord_Click:
MsgBox Err.Description
Resume Exit_DuplicateRecord_Click

End Sub

When i try to execute the code via a comand button, i get an error and the duplicate record operation does not occur. one thing i noticed is that i have a lot of lookup fields (i.e. FK's to lookup tables one-to-many relationships) in underlying table being populated by the form. i've created combo boxes on the form to populate the FK's in the underlying table. the error that occurs when trying to use the above code produces a "paste errors" table and in that paste errors table instead of the bound column values from the combo boxes (i.e. PK values from the lookup tables) it shows the display values from the combo boxes. i'm not sure if this has do with anything, but i couldn't figure out why it was doing this.

does anyone have any ideas how i could get this duplicate record procedure to work?

many thanks for any help or suggestions.
 
Try this: the logic is straightforward. The Primary key will look after itself. If you have a subform embedded, it is a bit more complicated.

Private Sub cmdCopyQuote_Click()
Dim dbs As DAO.Database, Rst As DAO.Recordset
Dim F As Form

Set dbs = CurrentDb
Set Rst = Me.RecordsetClone

On Error GoTo Err_Copy_Quotation

With Rst
.AddNew
!Issue = Me!Issue + 1
![Quotation Date] = Me![Quotation Date]
!Title = Me!Title
!CustomerNumber = Me!CustomerNumber
!Notes = Me!Notes
!Status = Me!Status
.Update
.Move 0, .LastModified
End With
Me.Bookmark = Rst.Bookmark

'
Exit_Copy_Quotation:
Exit Sub

Err_Copy_Quotation:
MsgBox Error$
Resume Exit_Copy_Quotation
End Sub
 

Users who are viewing this thread

Back
Top Bottom