?
Solved

In VB Use SQL to Copy a table

Posted on 2001-08-10
4
Medium Priority
?
183 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 1200 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…
Suggested Courses

752 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