|
-
Mar 21st, 2002, 05:57 AM
#1
Thread Starter
Hyperactive Member
Create a table
Is there any way to create a new table in an Access database from VB?
With ADOX for example.
-
Mar 21st, 2002, 06:17 AM
#2
Frenzied Member
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
-
Mar 21st, 2002, 06:22 AM
#3
Thread Starter
Hyperactive Member
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.
-
Mar 21st, 2002, 06:54 AM
#4
Frenzied Member
The answer is yes. But there's no need for worship - just hard cash...
-
Mar 21st, 2002, 06:59 AM
#5
Thread Starter
Hyperactive Member
Yahoo!
I can keep all those bloody users away from my database.
Thanks a lot.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|