Adding a new field to a table 
Author Message
 Adding a new field to a table

I am trying to write a routine that adds a yes/no boolean field to an
already built table.

At the moment the code comes close, and will add a boolean field, but seems
to be in a differnent format to what I would expect.

This is the code

Public Sub AddNewMailList()
On Error Resume Next
Dim dbs As Database
Dim tbl As TableDef
Dim fld As New Field

Set dbs = DBEngine.Workspaces(0).OpenDatabase(GetPathToMainData)
Set tbl = dbs.TableDefs("wk-MailingLists")
Set fld = tbl.CreateField("NewBoolean", dbBoolean)

tbl.Fields.Append fld
dbs.TableDefs.Refresh

Set dbs = Nothing

End Sub

I am not sure if this is the best way of doing it or if I need to set other
properties after the field has been created. (Nor am I sure how to change
the properties of the field after it is created, but I will worry about
that when I have to....)

Any help or comments would be great.

Thanks,

Mike



Sat, 01 Jul 2000 03:00:00 GMT  
 Adding a new field to a table

I personally think the ALTER TABLE SQL statment is very easy to
use.

DIM db as database
set db = CurrentDB()
db.Execute"ALTER TABLE ADD ..."

I hope this helps.

Jim Bailey
TeamB

Quote:

> I am trying to write a routine that adds a yes/no boolean field to an
> already built table.

> At the moment the code comes close, and will add a boolean field, but seems
> to be in a differnent format to what I would expect.

> This is the code

> Public Sub AddNewMailList()
> On Error Resume Next
> Dim dbs As Database
> Dim tbl As TableDef
> Dim fld As New Field

> Set dbs = DBEngine.Workspaces(0).OpenDatabase(GetPathToMainData)
> Set tbl = dbs.TableDefs("wk-MailingLists")
> Set fld = tbl.CreateField("NewBoolean", dbBoolean)

> tbl.Fields.Append fld
> dbs.TableDefs.Refresh

> Set dbs = Nothing

> End Sub

> I am not sure if this is the best way of doing it or if I need to set other
> properties after the field has been created. (Nor am I sure how to change
> the properties of the field after it is created, but I will worry about
> that when I have to....)

> Any help or comments would be great.

> Thanks,

> Mike



Sun, 02 Jul 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to modified existing field and add new field in existing table for Access database

2. Create new fields in a table based off of fields in another table

3. Create new field in existing table exactly like field in second table

4. Adding a new Field to a Linked (or Imported) Table

5. Crystal Report cannot see new field that is added to MS Access table

6. Adding new fields to an existing table

7. Add New Field in existing Table (VB6)

8. I need to be able to add new fields to a MS Access table via VbScript

9. I need to be able to add new fields to a MS Access table via VbScript

10. Adding a new field to an existing table via ADOX

11. need help please:joined tables,add new entries based on one table columns

12. need help please:joined tables,add new entries based on one table columns

 

 
Powered by phpBB® Forum Software