Results 1 to 6 of 6

Thread: another db question? adding sheets

  1. #1

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    another db question? adding sheets

    how do i add new tables to a mdb database and then alter the fields?

  2. #2
    Member
    Join Date
    Aug 2000
    Posts
    60
    By using the TableDef and Field objects, all documented. If you need sample code, just ask.
    Barend
    JHB-SA

    Nothing is impossible, except skiing through a revolving door.

  3. #3

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    i do, that's why i did!

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    This uses DAO (bit different to your last question), hopefully someone else will post a ADO way of doing this but...

    Code:
    Dim db as database, rs as recordset
    
    Set DB = DAO.OpenDatabase("C:\A_database_Here.mdb)DB.Execute "CREATE TABLE TableName_Here" & "(Column_Name_Here TEXT)"
    Set rs = db.openrecordset("TableName_Here")
    (the text bit at the end I think is optional, but specifies the type of column - what format the entries are in ie number, text etc...)

    Hope this helps

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5
    Member
    Join Date
    Aug 2000
    Posts
    60
    Here's another way of doing it with only DAO objects.
    Hope this helps. I haven't really had to use it in ADO yet but I'll check it out.

    Dim dbCheck As Database
    Dim tdfCheck As TableDef
    Dim fldCheck As Field

    'If the database exists, open it.
    Set dbCheck = DBEngine.OpenDatabase("c:\MyDB.mdb")
    'Else Create the database.
    Set dbCheck = DBEngine.CreateDatabase("c:\MyDB.mdb", dbLangGeneral)

    'Create the table definition
    Set tdfCheck = dbCheck.CreateTableDef("MyTable")

    'Create the field
    Set fldCheck = tdfCheck.CreateField("MyField", dbText, 20)
    'Set up field parameters.
    fldCheck.AllowZeroLength = False
    fldCheck.Required = True
    'Append the field definition to the table definition.
    tdfCheck.Fields.Append fldCheck

    'Append the table definiition to the database
    dbCheck.TableDefs.Append tdfCheck

    'Close the database explicitly, otherwise the changes won't be saved.
    dbCheck.Close
    Barend
    JHB-SA

    Nothing is impossible, except skiing through a revolving door.

  6. #6

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    thanks

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