Link to home
Start Free TrialLog in
Avatar of kazraver
kazraver

asked on

In VB Use SQL to Copy a table

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
ASKER CERTIFIED SOLUTION
Avatar of idorey
idorey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kazraver
kazraver

ASKER

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.
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!)
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