Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Transfer records from one table to another

Posted on 2009-07-11
9
Medium Priority
?
156 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 1600 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 400 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
Suggested Courses

783 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