I'm trying to add a new table to a SQL Server database using the following
procedure. On the line where I append the table to the collection, I get the
following error: "Runtime Error '-2147024809(80070057);' The parameter is
incorrect."
Is it possible to create a table in this way? Does anyone know what the
problem is? Thanks for your help.
Public Sub CreateSQLTable(DatabaseName As String, ServerName As String,
UserID As String, Password As String, TableName As String)
' This procedure creates a new table in a database
Dim oConn As ADODB.Connection
Dim oCatalog As New ADOX.Catalog
Dim oTable As New ADOX.Table
Dim sData As String
'Create a new ADO connection and set it equal to a file on the
'sql server
Set oConn = New ADODB.Connection
oConn.Open "Provider=SQLOLEDB;Data Source=" & ServerName & ";User ID=" &
UserID & ";Password=" & Password & ";"
'set the database and table and add assign the new table a name
oCatalog.ActiveConnection = oConn
Set oTable.ParentCatalog = oCatalog
oTable.Name = TableName
'append the table to the database
oCatalog.Tables.Append oTable ' ERROR HAPPENS HERE
'clean up
oCatalog.ActiveConnection = Nothing
Set oCatalog = Nothing
Set oTable = Nothing
Set oConn = Nothing
End Sub