469,330 Members | 1,326 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

using command button to copy record in a form

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
5 27326
Rabbit
12,516 Expert Mod 8TB
Use the On Click event to run a DoCmd.RunSQL Append.
Feb 9 '07 #2
NeoPa
32,181 Expert Mod 16PB
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
rajq
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
32,181 Expert Mod 16PB
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
32,181 Expert Mod 16PB
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.

Similar topics

1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.