Is there any way to create a new table in an Access database from VB?
With ADOX for example.
Printable View
Is there any way to create a new table in an Access database from VB?
With ADOX for example.
Yep. ADOX would be a good place to start. This'll start you off:
VB Code:
Private Sub CreateTable() Dim cat As ADOX.Catalog Dim tbl As ADOX.Table Dim col As ADOX.Column 'get the catalog Set cat = New ADOX.Catalog cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\mynew.mdb" 'create a column Set col = New ADOX.Column With col .Name = "PK" .Type = adInteger End With 'create the table Set tbl = New ADOX.Table With tbl .Name = "NewTable" .Columns.Append col End With 'append the table cat.Tables.Append tbl End Sub
PilgrimPete
Thanks for that.
Will this actually add the new table to the database itself, or just to the catalog.
So if I look at the database later NewTable will actually be there.
If you answer yes to this I'll worship the ground you walk on.
The answer is yes. But there's no need for worship - just hard cash... :D
Yahoo!
I can keep all those bloody users away from my database.
Thanks a lot.