Solved

Transfer records from one table to another

Posted on 2009-07-11
9
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 127
TT Auto Dashboard 13 101
Set WorkSheet  not Working 9 52
Remove Exif Orientation before adding image to db 9 42
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 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