Duplicating a record

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,
 
G

Guest

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
 
G

Guest

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
 
G

Guest

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.
 
G

Guest

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
 
G

Guest

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
 
G

Guest

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??
 

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

Top