Solved

Transfer records from one table to another

Posted on 2009-07-11
9
148 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now