By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,695 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,695 IT Pros & Developers. It's quick & easy.

using command button to copy record in a form

P: 1
i am inputting records using a form. how do i put a command button on the form that will copy the record i just input----sometimes i have the same record that needs to be put in 3 or 4 times and i would rather just be able to click a button and copy it.
Feb 9 '07 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 10K+
P: 12,427
Use the On Click event to run a DoCmd.RunSQL Append.
Feb 9 '07 #2

Expert Mod 15k+
P: 31,754
I would put code in your Form_BeforeUpdate procedure, that sets the Defaults for the fields to be duplicated, to the new values. This way you will only save them as a duplicate (or more likely a partial duplicate) when the operator has chosen to add the new record. Defaults will not effect updates of existing records.
Feb 10 '07 #3

P: 1
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdDuplicate_Click()
  2. On Error GoTo Err_cmdDuplicate_Click
  5.     DoCmd.RunCommand acCmdSelectRecord
  6.     DoCmd.RunCommand acCmdCopy
  7.     DoCmd.RunCommand acCmdRecordsGoToNew
  8.     DoCmd.RunCommand acCmdSelectRecord
  9.     DoCmd.RunCommand acCmdPaste
  11. Exit_cmdDuplicate_Click:
  12.     Exit Sub
  14. Err_cmdDuplicate_Click:
  15.     MsgBox Err.Description
  16.     Resume Exit_cmdDuplicate_Click
  18. End Sub
Feb 8 '08 #4

Expert Mod 15k+
P: 31,754
Rajq's code is pretty well what you want - but be careful if you have any unique indexes in your record. In that case it will fail.
If you don't have any in your table then this should be perfect.
Feb 8 '08 #5

Expert Mod 15k+
P: 31,754
A (possibly) related thread (Copy Record Structure (Related Records)).
Feb 27 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.