Hey I was wondering about how you would move tables from one db to another.
So far I have defined the function TransferData and I have defined the sConn from my source db to give to cnn and set sourceCat with it.
When I look in the debugger I can see that the tables are showing and the connection is right.
The problem is with my targetCat where I have tried giving it the currentproject.connection as active connection. But that wont do it..
Then I tried defining a sConnOne which is the other db connection string then i created another adodb connection cnnOne to give it the sConnOne connection.
I then looked in the debugger and saw that it was indeed the right tables it was showing from sConnOne.
But then when I ran the code TransferData("TableTest") I get a errorcode 3251.
Function TransferData(tableName As String)
Dim cnn As New ADODB.Connection
Dim cnnOne As New ADODB.Connection
Dim sourceCat As New ADOX.Catalog
Dim targetCat As New ADOX.Catalog
Dim sConn As String
Dim sConnOne As String
sConn = "Driver={SQL Server};" & _
"SERVER=SRV-SQL-TEST;" & _
"Trusted_Connection=Yes;" & _
"DATABASE=" & getDatabaseNameDev
sConnOne = "Driver={SQL Server};" & _
"SERVER=SRV-SQL-TEST;" & _
"Trusted_Connection=Yes;" & _
"DATABASE=" & getDatabaseName
cnn.Open sConn
Set sourceCat.ActiveConnection = cnn
'cnnOne.Open sConnOne
Set targetCat.ActiveConnection = CurrentProject.Connection
'cnnOne
Dim sourceTable As ADOX.Table
Set sourceTable = sourceCat.Tables(tableName)
Dim newTable As New ADOX.Table
Set newTable.ParentCatalog = targetCat
newTable.name = sourceTable.name
Dim sourceCol As ADOX.Column
Dim newCol As ADOX.Column
For Each sourceCol In sourceTable.Columns
Set newCol = New ADOX.Column
newCol.name = sourceCol.name
'newCol.Type = sourceCol.Type
newCol.DefinedSize = sourceCol.DefinedSize
newCol.ParentCatalog = targetCat
newTable.Columns.Append newCol
Next sourceCol
targetCat.Tables.Append newTable
End Function