473,395 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 8641
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

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

Similar topics

2
by: Dianna K. | last post by:
I have a dataview which I am assigning to a Datatable (I am doing this because currently Crystal Reports will not accept a dataview as a Reportsource -- The recommended work-around is to assign...
4
by: stelladiary2004 | last post by:
Hi! I would appreciate some help with this (basic) question. I need to copy an 2D array x to another 2D array y. I know how to do it copying element by element, but I would like to use a faster...
16
by: laclac01 | last post by:
I have developed my own copy function for coping my own dynamic memory structure. It works, but I feel its not too efficient. There must be a quicker way to copy the data. In some of the...
6
by: Fan Ruo Xin | last post by:
I try to copy a table from production system (DB2 UDB EEE V7.2 + fixpak5) to the testing system (DB2 UDB V8.1 + fixpak4a). I moved the data from productions system by using the following steps:...
2
by: michael sorens | last post by:
I tried to do a simple operation on a Windows Form in VS2005 inside a key_down handler: if (e.Control && e.Shift && e.KeyCode == Keys.V) { int selectedRowIndex =...
1
by: sansann | last post by:
I m working on project. The idea is, select 1 row and add to another Msflexgrid. Instead of 20 rows i might want to select 5 or 10 rows only from Mshflexgrid1 to be add in Mshflexgrid2. coding...
14
by: Yas | last post by:
Hello, I have 2 tables, Table1 and Table2. I have copied all data from Table1 to Table2. However Table1 is dynamic it has new rows added and some old rows modified everyday or every other...
5
by: Sieldan | last post by:
I'm trying to throw some data around so that I can manipulate it more easily. Unfortunately, I don't really know what I'm doing. :) So I'm creeping my way through it step by step. What I have done...
0
by: damiencarr | last post by:
i have a spreadsheet/worksheet called "NTH_Alliance" containing rows of related data grouped together under different headings, that are named as different weeks (e.g. Week 5 (26/01/2009 -...
4
by: hiitzsdg | last post by:
Hi All, I am completely new to VBA and I am trying to develop a macro in a workbook (Backup.xls). The main functionality of the macro is: 1. It would open another workbook (Source.xls). 2....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.