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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!)
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.OL EDB.4.0;Da ta Source=" + App.Path + "\<DB NAME>"
+ ";"
MyConn.Open
MyConn.Execute "SELECT <TABLE NAME>.*,* INTO <NEW TABLENAME> FROM <TABLE NAME>"
MyConn.Close
Set MyConn = Nothing
Using the code supplied above:
Dim MyConn As ADODB.Connection
Set MyConn = New ADODB.Connection
MyConn.ConnectionString = "PROVIDER=Microsoft.Jet.OL
+ ";"
MyConn.Open
MyConn.Execute "SELECT <TABLE NAME>.*,* INTO <NEW TABLENAME> FROM <TABLE NAME>"
MyConn.Close
Set MyConn = Nothing
ASKER
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.