Duplicate Button Baffling Me



I generated the standard duplicate button from Access; I used it in another
form and it works great; in this other form I can't get it to work right for
anything. I checked all the settings of what I did in the previous form and
everything is the same; however I do have a field that cannot have a
duplicate name, so I am not completely sure if that is the reason why this
isn't working.

But basically when I select the button, the record is copied but none of the
information is filled in. It's late in the day; I'm sure it's something

"allow additons and deletions is set to "Yes""

Private Sub cmdduplcable_Click()
On Error GoTo Err_cmdduplcable_Click

Dim NewCableTag As Variant

NewCableTag = InputBox("Enter a New Cable Tag:", "New Cable Tag", "XXX",
1000, 1000)

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdPasteAppend 'Paste Append

Me.txbDESIGN.Value = NewCableTag

Exit Sub

MsgBox Err.Description
Resume Exit_cmdduplcable_Click
End Sub

Allen Browne

There are lots of cases where that wizard's code doesn't work. From memory,
it handles autonumbers okay, but gets quite confused about calculated
controls and fields from other tables (if the form's source is a multi-table

A better solution is to AddNew on the RecordsetClone of the form. This
allows you to copy selected fields, and assign others in specific ways. For
example, you might want to duplicate an invoice, but have it dated today.

There's an example of how to do that here:
Duplicate the record in form and subform
(You can just ignore the bit about duplicated the related records in the
subform as well.)

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question