472,127 Members | 1,601 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

How to copy rows

134 100+
Once I have search the row that I want, How do I copy the entire row content and insert into a new row with the same content using vba .Can the "GetRows" work, how does it work ?, Is there a better way beside define the columns one by one, as my row have more than 20 columns.
Dec 21 '06 #1
6 8494
missinglinq
3,532 Expert 2GB
Here's the code that Access generates if you create a button using the Command Button Wizard and assign the Duplicate Record function to it.
Expand|Select|Wrap|Line Numbers
  1.    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
  2.    DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
  3.    DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 
  4.  
On a Single Form or Continuous Form you can place it behind a command button. On a Datasheet form you need to place it on something like the DoubleClick event of a text control.

If any of the components of your row is Primary Key or set to no duplicates in the table definitions, after Access inserts the copy you must change the data in these controls before saving the newly created record, otherwise Access will throw an error and the new record won't be saved.
Dec 21 '06 #2
jamesnkk
134 100+
Here's the code that Access generates if you create a button using the Command Button Wizard and assign the Duplicate Record function to it.
Expand|Select|Wrap|Line Numbers
  1.    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
  2.    DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
  3.    DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 
  4.  
On a Single Form or Continuous Form you can place it behind a command button. On a Datasheet form you need to place it on something like the DoubleClick event of a text control.

If any of the components of your row is Primary Key or set to no duplicates in the table definitions, after Access inserts the copy you must change the data in these controls before saving the newly created record, otherwise Access will throw an error and the new record won't be saved.
After I clicked the command button, It does create a new row, but an empty row
Dec 21 '06 #3
missinglinq
3,532 Expert 2GB
Of course it does! You mean it creates the duplicate row and a blank row, right? The last row of any continuous form or datasheet form is always blank, ready for a new record to be added! That's the same thing it would exhibit if you'd clicked on the New Record button and manually entered a record!
Dec 21 '06 #4
jamesnkk
134 100+
Of course it does! You mean it creates the duplicate row and a blank row, right? The last row of any continuous form or datasheet form is always blank, ready for a new record to be added! That's the same thing it would exhibit if you'd clicked on the New Record button and manually entered a record!
I am not sure I got your message right, It does create a blank row, but did not duplicate the record in the table.I couldn't find a duplicate record in the table.

I understand the last row is alway blank ready for a new record.
Dec 21 '06 #5
missinglinq
3,532 Expert 2GB
I think the problem is that you're using a continuous form. I was mistaken in saying you could put the code behind a command button on a continuous form, you can only do this on a Single View form. When you click on the button on a continuous form, the focus is now on the button and there is no selected record, so Access doesn't know what to copy. You'll need to place the code behind the DoubleClick event for one of your controls (which is how I tested it.) I'd use whichever control is at the beginning of your row.
Dec 22 '06 #6
jamesnkk
134 100+
I think the problem is that you're using a continuous form. I was mistaken in saying you could put the code behind a command button on a continuous form, you can only do this on a Single View form. When you click on the button on a continuous form, the focus is now on the button and there is no selected record, so Access doesn't know what to copy. You'll need to place the code behind the DoubleClick event for one of your controls (which is how I tested it.) I'd use whichever control is at the beginning of your row.
It Alright, I have to use Insert into table to solve, but that serious.
Dec 23 '06 #7

Post your reply

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

Similar topics

2 posts views Thread by Dianna K. | last post: by
4 posts views Thread by stelladiary2004 | last post: by
6 posts views Thread by Fan Ruo Xin | last post: by
2 posts views Thread by michael sorens | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.