Solved

vb recordset copy table

Posted on 2006-11-28
8
2,191 Views
Last Modified: 2008-01-09
I have two databases and would like to copy one table into another in the other database.

I can read all the information into a recordset.

I am looking for an easy way to put the old data into the new table without having to loop and specify the insert statement.

I am trying to copy table results into results_old in the new db.
0
Comment
Question by:jackjohnson44
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 15

Expert Comment

by:cquinn
ID: 18028801
Use a make table query


SELECT INTO results_old FROM results
0
 

Author Comment

by:jackjohnson44
ID: 18028822
this is across 2 databases, how can you do that with one statment and one connection?
0
 
LVL 5

Expert Comment

by:IThema
ID: 18029121
Hi, you can link from one database to another. The way to to this depends on the type of database. I could give you examples for SQL Server and Access databases. Once the link is made, you could use cquinn's comment to transfer the data.

However, if this is something you'd only like to do once, you might be better off using the SQL Server Data Transformation Services (DTS). This is an easy tool that enables you to copy data and tables from one datasource to another data source. DTS doesn't care wether it's an Access, MySQL, SQL Server, Excel, Oracle or ASCII data source. If it's two MS Access tables, you could just open both databases in different instances of MS Access, and simply copy/paste the table.

Good luck.


Luc
0
 
LVL 15

Assisted Solution

by:cquinn
cquinn earned 200 total points
ID: 18029136
From within the target database run this query

SELECT INTO results_old FROM results IN "C:\OldDatabase.mdb"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jackjohnson44
ID: 18029496
I would like to use visual basic.

I currently have a program that gets data from one database loops throught the recodset and I use insert statements to put it in the other database.  I don't want to have to specify the column names and do an insert statement.  Can someone help me accomplish this?

If your solution does not include vb, please do not respond, it is not what I am looking for.

Thanks
0
 
LVL 27

Expert Comment

by:Ark
ID: 18033256
cquinn already answered your question. VB code:
conn.Execute SELECT INTO results_old FROM results IN "C:\OldDatabase.mdb", , adExecuteNoRecords

where conn is your connection to new database
0
 
LVL 27

Accepted Solution

by:
Ark earned 300 total points
ID: 18033262
Opps, sorry, should be

conn.Execute "SELECT INTO results_old FROM results IN ""C:\OldDatabase.mdb""", , adExecuteNoRecords
0
 
LVL 5

Expert Comment

by:IThema
ID: 18035121
Ark and cquinn are right. By using the IN-statement, you don't even need to specify a link first. I think that's the easiest approach.


Good luck
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Input past end of file vbs script 9 82
change vba from autofit to 13.5 width? 4 28
MsgBox 2 47
Question about INSTR  - need to extract data MS ACCESS query 6 54
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now