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

Copy and pasting within a form

P: 18
I have the main form where employees enter "issues". Some issues have fields that are the same. My fields are

Issue ID (auto)
Entered BY
Issue Type
Request from
Assigned to

Is there a way to have a "Copy" button that would copy all of the information in the form, and then paste it into the same form but in a new record?

Example...Say I have an issue that needs to be assigned to 2 different departments, I want to enter a new issue (we'll just say its issue 9) then have a copy button that would copy all of that information then open issue 10 and paste it in there.

Thank you for any help in advanced.

Oct 10 '08 #1
Share this Question
Share on Google+
6 Replies

P: 56
create a command button (cmdCopy) on the form and paste this code onto the "On Click" event
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand acCmdSelectRecord
  2.   DoCmd.RunCommand acCmdCopy
  3.   DoCmd.GoToRecord , , acNewRec
  4.   DoCmd.RunCommand acCmdPaste
Or you can use the access wizzard to create a "Duplicate Record" command. Here is the code from the wizzard:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCopy_Click()
  2. On Error GoTo Err_cmdCopy_Click
  3.     DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
  4.     DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
  5.     DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
  7. Exit_cmdCopy_Click:
  8.     Exit Sub
  10. Err_cmdCopy_Click:
  11.     MsgBox Err.Description
  12.     Resume Exit_cmdCopy_Click
  14. End Sub
hopes this'll help.
Oct 10 '08 #2

Expert Mod 15k+
P: 31,709
The former would be the recommended way. The wizard-created code is rubbish :(
Oct 11 '08 #3

P: 18
How would i code it so that it only copies a few of the fields, not all of them?

SUpposed I just want Product, Entered BY, Issue Type, Priority, Request from, and Status to be copied and pasted onto the next issue.
Oct 13 '08 #4

Expert Mod 15k+
P: 31,709
That would be an entirely different issue.

You would need to save your own copies of the data required, move to the rnext record, then update the relevant controls with the saved data.
Oct 13 '08 #5

Expert Mod 2.5K+
P: 2,545
Hi. I suggest you consider something different which may help with your requirement to 'copy' values from one record to the next - don't copy them, set the default value for the controls concerned instead.

How is this done? In the After Update event of each control whose value you want to carry forward simply enter the following event code, substituting the correct name of the control in each case:

Expand|Select|Wrap|Line Numbers
  1. Me![your control name].DefaultValue = "'" & Me![your control name] & "'"
This will set the default value for the control concerned to whatever was last entered. The default value property is a string (regardless of the type of the underlying field), hence the use of single quotes on either side of the value of the control.

I use this technique a lot when I want to carry forward field values from record to record. It's a lot easier and safer to set defaults than it is to copy values from one record to another. Using defaults there is then no question of accidentally creating new records at the wrong time, which is what will happen if you copy values into a blank record on a button press, say.

Oct 13 '08 #6

Expert Mod 15k+
P: 31,709
That's a good point Stewart. I fully endorse that.
Oct 13 '08 #7

Post your reply

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