By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,668 Members | 1,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,668 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


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

NeoPa
Expert Mod 15k+
P: 31,487
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
  3.  
  4.  
  5.     DoCmd.RunCommand acCmdSelectRecord
  6.     DoCmd.RunCommand acCmdCopy
  7.     DoCmd.RunCommand acCmdRecordsGoToNew
  8.     DoCmd.RunCommand acCmdSelectRecord
  9.     DoCmd.RunCommand acCmdPaste
  10.  
  11. Exit_cmdDuplicate_Click:
  12.     Exit Sub
  13.  
  14. Err_cmdDuplicate_Click:
  15.     MsgBox Err.Description
  16.     Resume Exit_cmdDuplicate_Click
  17.  
  18. End Sub
Feb 8 '08 #4

NeoPa
Expert Mod 15k+
P: 31,487
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

NeoPa
Expert Mod 15k+
P: 31,487
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.