
Problems creating a table based on a stored Query in an Access-MDB
Following szenario:
1.) Creating a MS-Access DB via ADOX
2.) Creating an SQL Pass-through Queries ("MyQuery")
3.) Creating a new Table by executing an command based on the Query ("SELECT
* INTO MyTable FROM MyQuery")
The problem I have is that the command seems to be executed twice. I always
get the error "Table <MyTable> already exists" when the command is executed.
Has anybody an idea whats going wrong ?
Thanks in advance !!
Peter.
============================================================================
==============================================
Dim catDB As ADOX.Catalog
Dim cmd As ADODB.Command
Dim cmd2 As ADODB.Command
Set catDB = New ADOX.Catalog
catDB.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\my.mdb"
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = catDB.ActiveConnection
.CommandText = "select * from betmandmodul"
.Properties("Jet OLEDB:ODBC Pass-Through Statement") = True
.Properties("Jet OLEDB:Pass Through Query Connect String") =
"ODBC;DSN=kfz;UID=uid;PWD=pwd;"
End With
catDB.Procedures.Append "MyQuery", cmd
Set cmd2 = New ADODB.Command
With cmd2
.ActiveConnection = catDB.ActiveConnection
.CommandText = "select * INTO MyTable from MyQuery"
End With
cmd2.Execute