Results 1 to 5 of 5

Thread: Create a table

  1. #1

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479

    Create a table

    Is there any way to create a new table in an Access database from VB?
    With ADOX for example.

  2. #2
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    Yep. ADOX would be a good place to start. This'll start you off:

    VB Code:
    1. Private Sub CreateTable()
    2.     Dim cat As ADOX.Catalog
    3.     Dim tbl As ADOX.Table
    4.     Dim col As ADOX.Column
    5.    
    6.     'get the catalog
    7.     Set cat = New ADOX.Catalog
    8.     cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\mynew.mdb"
    9.    
    10.     'create a column
    11.     Set col = New ADOX.Column
    12.     With col
    13.         .Name = "PK"
    14.         .Type = adInteger
    15.     End With
    16.    
    17.     'create the table
    18.     Set tbl = New ADOX.Table
    19.     With tbl
    20.         .Name = "NewTable"
    21.         .Columns.Append col
    22.     End With
    23.    
    24.     'append the table
    25.     cat.Tables.Append tbl
    26.    
    27. End Sub

  3. #3

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    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.

  4. #4
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    The answer is yes. But there's no need for worship - just hard cash...

  5. #5

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    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
  •  



Click Here to Expand Forum to Full Width