Duplicating a record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a data entry form used to populate a table. There are about 25 fields
to fill in. The operators sometimes have two records that are almost
identical - except for the order number (primary key) and a few dates. Is
there a way to program a button to duplicate the record, except for the order
number and dates, then prompt to enter the new order number?

I tried a command button using:

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

but it duplicates the entire record, then I get an error for a duplicate
primary key.

Thanks,
 
I use the following code on a main form (no subforms) to copy a record to the
current form and allow the user to manipulate the record as desired.

Private Sub cmdDuplicate_Click()
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand acCmdRecordsGoToNew
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdPaste
End Sub
 
Hi Rowiga,

Thanks for the idea, but that still doesn't solve the problem of duplicating
the primary key, unless I'm not following what you're doing. I was hoping to
do this on the same form that they usually use for data entry.

Thanks,

Marc
 
If OrderNumber is your primary key Access won't allow you to save the record
again with the same primary key value. The value of OrderNumber has to be
changed to save the new record. This can be used on the same form that the
user always uses.
 
When I use your code below, I get an error message right away that says the
primary key cannot be duplicated, so Access does not paste in the duplicate.
It's not allowing me to change the order number.

Marc
 
Hmmmm...I don't understand why you're getting a primary key violation on the
form. I don't have a problem unless I try to save the copied record without
changing the primary key. Anyway, I thought that this was a simple solution
but maybe we have different Access versions or something. Here's a link to
Allen Browne's solution for doing this. I hope this or someone else can
answer your question.

http://members.iinet.net.au/~allenbrowne/ser-24.html
 
Rowiga:

I see that you have a code to create a duplicate of a record that allow you
to pass only a few fields... Can you show me an example of it? I try the
code that you wrote but it create a full duplicate. Can you help me??
 
Back
Top