Add a column to a table using ADO

  • Thread starter Thread starter dave
  • Start date Start date
D

dave

I need to add a column to a table using ADO.

The following works, but only for a new table. How should I change this to
alter an existing table?


Dim strConn
Dim Catalog As New ADOX.Catalog
Dim Table As ADOX.Table

Set Catalog = New ADOX.Catalog

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data.mde"
Catalog.ActiveConnection = strConn

Set Table = New ADOX.Table
Table.Name = "tblExistingTable"
Table.Columns.Append "NewColumn", adBoolean
Catalog.Tables.Append Table
 
Why not use a Data Definition Language query from code like:

docmd.Runsql "alter table [tblExistingTable] add column [NewColumn] yesno"

Should work OK.

Ron W
 
Back
Top