Solved

Transfer records from one table to another

Posted on 2009-07-11
9
150 Views
Last Modified: 2012-05-07
I am trying to select certain records from one table and then place ALL the values retrieved into another table.

For example, if I retrieve all the records (Text1,Text4,Text5,Text7) for Table A.  How can I save the records temporarily, so that I can close the current table and then open another table so that I can place all the data in Table B?

Hope that makes sense.  
If conn.State = adStateClosed Then
        conn.Open "Provider=sqloledb;Data Source=" & ConnectionIP & ",1433;Network Library=DBMSSOCN;Initial Catalog= CAPRegistration; User ID=sa;Password=xxxx"
        End If
        
        esql = "select Text1 , Text4, Text5, Text7 From tblRegistration Where Committee = " & ravi & DataGridOrganization & ravi

Open in new window

0
Comment
Question by:al4629740
  • 4
  • 4
9 Comments
 
LVL 13

Accepted Solution

by:
game-master earned 400 total points
ID: 24834137


good evening!
try sumthing like this...

'assuming u already have connection...

dim rs as new adodb.recordset


set rs = conn.execute("<your select statement here>")

do until rs.eof

       conn.execute("Insert into YOURTABLE (field1, field2, field3, field4) values ('" & rs!Text1 & "' ,'" & rs!Text2 & "'  ,'" & rs!Text3 & "'     ,'" & rs!Text4 & "'  ")

rs.movenext
loop


i hope i can give u idea...

game-master
0
 

Author Comment

by:al4629740
ID: 24834268
Thank you.

YOURTABLE is my destination table?

also, what does "rs!" represent?
0
 
LVL 10

Assisted Solution

by:3_S
3_S earned 100 total points
ID: 24835668
-Are both tables in same database  
-do you need to add extra field in table b

Can you use an select insert into?
INSERT INTO TABLEB ("Text1 , Text4, Text5, Text7) select Text1 , Text4, Text5, Text7 From tblRegistration

This way you can copy the records in one command and you don't need a loop
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:al4629740
ID: 24835767
They are in separate dbs.

Also, yes I need to add a new record when pasting the fields
0
 
LVL 13

Expert Comment

by:game-master
ID: 24836651


good morning!

if they're in different dbase, then u need 2 connection string...



game-master
0
 

Author Comment

by:al4629740
ID: 24837274
will it automatically add a new record?

INSERT INTO TABLEB ("Text1 , Text4, Text5, Text7) select Text1 , Text4, Text5, Text7 From tblRegistration
0
 
LVL 13

Expert Comment

by:game-master
ID: 24837281

YES IT WILL...

THE RS! MEANS YOUR POINTING ON THE REcords on your 'rs' recordset...



game-master
0
 

Author Comment

by:al4629740
ID: 24837333
INSERT INTO TABLEB ("Text1 , Text4, Text5, Text7) select Text1 , Text4, Text5, Text7 From tblRegistration

Is there suppose to be quotation marks before Text1 ?
0
 
LVL 13

Expert Comment

by:game-master
ID: 24837366


REMOVE THE QUOTATION MARK BEFORE THE TEXT1....


0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 57
VB 6.0 printer how to align 6 62
Excel - Save a copy of work book 13 84
How to set the sa password in a vb6 code for sql connection 9 52
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question