Solved

In VB Use SQL to Copy a table

Posted on 2001-08-10
4
181 Views
Last Modified: 2010-05-02
Is there a way (I KNOW there must be!) to use an SQL statement from VB, to copy (Duplicate) a table and its data and data type settings?

I have tried to duplicate the table in code but I am unable to set the properties of each field, so duplicating it like this would be best.

Thanks
0
Comment
Question by:kazraver
[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
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
idorey earned 300 total points
ID: 6371624
Hey Kaz! How are you? Long time (Bla bla)

Try this:

Dim MyConn As ADODB.Connection
Dim MyTable As ADODB.Recordset
Set MyConn = New ADODB.Connection
MyConn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\<DB NAME>" + ";"
MyConn.Open
Set MyTable = New ADODB.Recordset
MyTable.Open "SELECT <TABLE NAME>.*,* INTO <NEW TABLENAME> FROM <TABLE NAME>", MyConn, adOpenDynamic, adLockOptimistic
If MyTable.State = adStateOpen Then MyTable.Close

If this works mail me. I just moved and I need to give you the address.
0
 

Author Comment

by:kazraver
ID: 6371630
Whoa! Thats was quick!

I just realized that I posted the blasted Q twice!! Oh well off to Support!

I will test this later and drop you a mail.
0
 

Author Comment

by:kazraver
ID: 6371650
Hey Cool! Thats worked okay. I got a bit confused there for a moment but it works just fine.

What you doing sitting on the VB Question section?

I will mail you later (I am at work right now!)
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6371658
idorey is correct though it is a slight waste of resources using a recordset object to do this. You can do the same thing using the execute method of the connection object:

Using the code supplied above:

Dim MyConn As ADODB.Connection
Set MyConn = New ADODB.Connection
MyConn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\<DB NAME>"
+ ";"
MyConn.Open
MyConn.Execute "SELECT <TABLE NAME>.*,* INTO <NEW TABLENAME> FROM <TABLE NAME>"
MyConn.Close
Set MyConn = Nothing
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

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…
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…
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…

696 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