woaini
asked on
Copy record from one table to another
Hi,
It has been a long time ago, I have seen a command in Ms Access
that able to copy 1 row of data and paste that entire row to another table. I wonder how to do that, instead to use something like this :
pRecordSet_1("field1") = pRecordSet_2("field1")
pRecordSet_1("field2") = pRecordSet_2("field2")
pRecordSet_1("field3") = pRecordSet_2("field3")
It not flexible to program that way, because each timethe field name change, I have to modify the program.
Thank a lot
Add comment 1 on 23 feb 2000 :
The 2 tables will have differents numbers of fields and we don't have to know those fields name.
So that the reason I need a command to able me copy record by record and paste to another table.
It has been a long time ago, I have seen a command in Ms Access
that able to copy 1 row of data and paste that entire row to another table. I wonder how to do that, instead to use something like this :
pRecordSet_1("field1") = pRecordSet_2("field1")
pRecordSet_1("field2") = pRecordSet_2("field2")
pRecordSet_1("field3") = pRecordSet_2("field3")
It not flexible to program that way, because each timethe field name change, I have to modify the program.
Thank a lot
Add comment 1 on 23 feb 2000 :
The 2 tables will have differents numbers of fields and we don't have to know those fields name.
So that the reason I need a command to able me copy record by record and paste to another table.
paasky's suggestion is by far the best, but if you have to do it one record at a time, you can just refer to the fields within each table by their index:
....
pRecordSet_1(0) = pRecordSet_2(0)
pRecordSet_1(1) = pRecordSet_2(1)
pRecordSet_1(2) = pRecordSet_2(2)
....
and so on. Then it won't matter is the fields change names, as long as the fields are in the same order in each table.
Wes
....
pRecordSet_1(0) = pRecordSet_2(0)
pRecordSet_1(1) = pRecordSet_2(1)
pRecordSet_1(2) = pRecordSet_2(2)
....
and so on. Then it won't matter is the fields change names, as long as the fields are in the same order in each table.
Wes
Try this:
INSERT INTO Table1
SELECT Table2.*
FROM Table2;
No field names involved here either.
INSERT INTO Table1
SELECT Table2.*
FROM Table2;
No field names involved here either.
srauda,
yes, that would do the job well if the two tables are identical and field names in same order.
yes, that would do the job well if the two tables are identical and field names in same order.
ASKER
Edited text of question.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank a lot Paasky !
woaini, glad we could help you.
wesleystewart, I posted a question for you because I used your idea for solving woaini's problem and want to share the points with you.
Regards,
Paasky
wesleystewart, I posted a question for you because I used your idea for solving woaini's problem and want to share the points with you.
Regards,
Paasky
This can be also done with a query. Here's an example how to copy a specific record from table1 to table2:
INSERT INTO Table2 ( ID, fldTable2 )
SELECT Table1.ID, Table1.fldTable1
FROM Table1
WHERE Table1.ID=[Enter ID you want to copy: ];
Regards,
Paasky