DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Adding a field to an existing Table

  1. #1
    Mike Guest

    Adding a field to an existing Table


    Hello,

    i thank you for any suggestions and help that you may provide.

    i am trying to use vb 6 code to add a new field to an existing table.

    i have not had any luck using TableDefs. i have the program creating a database
    and tables upon running, and skipping the creation if the tables already
    exist. the problem occurs because the program is installed in 6 business,
    and now they want an add-on. in order to do the add-on i need 1 field to
    be added to an employees database.

    Do i have to create a totally new table for to accomodate this field?

    thanks

    mike


  2. #2
    Paul Clement Guest

    Re: Adding a field to an existing Table

    On 9 May 2001 04:59:15 -0700, "Mike" <mlortie2@home.com> wrote:


    Hello,

    i thank you for any suggestions and help that you may provide.

    i am trying to use vb 6 code to add a new field to an existing table.

    i have not had any luck using TableDefs. i have the program creating a database
    and tables upon running, and skipping the creation if the tables already
    exist. the problem occurs because the program is installed in 6 business,
    and now they want an add-on. in order to do the add-on i need 1 field to
    be added to an employees database.

    Do i have to create a totally new table for to accomodate this field?

    thanks

    mike


    This code works fine for me:

    Function AddFieldsToAccessTable()

    Dim db As DAO.Database
    Dim tbl As DAO.TableDef

    Set db = OpenDatabase("c:\My Documents\db1.mdb")

    Set tbl = db.TableDefs("Table1")

    ' Create and append new Field objects
    With tbl
    ' The CreateField method will set a default Size
    ' for a new Field object if one is not specified.
    .Fields.Append .CreateField("TextField", dbText)
    .Fields.Append .CreateField("IntegerField", dbInteger)
    .Fields.Append .CreateField("DateField", dbDate)
    End With

    End Function


    Paul ~~~ pclement@ameritech.net
    Microsoft MVP (Visual Basic)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center