Creating table from Word VBA

  • Thread starter Thread starter Bo Hansson
  • Start date Start date
B

Bo Hansson

Using CreateField Method(DAO) I want to create new Acess tables from Word
VBA code, see following example

Set dbsDB = OpenDatabase(myDataBase)
Set tdf = dbsDB.CreateTableDef(myTable)
With tdf
tdf.Fields.Append .CreateField("Name", dbText, 50)
...and so on

This works fine, but how do I create a field containing a counter ?

/BosseH
 
You mean you want an Autonumber field?

Dim dbsDB As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set dbsDB = OpenDatabase(myDataBase)
Set tdf = dbsDB.CreateTableDef(myTable)
With tdf
tdf.Fields.Append .CreateField("Name", dbText, 50)
Set fld = .CreateField("Id", dbLong)
fld.Attributes = fld.Attributes + dbAutoIncrField
.Fields.Append fld
....and so on
 
Thanks a lot!

/BosseH
Douglas J. Steele said:
You mean you want an Autonumber field?

Dim dbsDB As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Set dbsDB = OpenDatabase(myDataBase)
Set tdf = dbsDB.CreateTableDef(myTable)
With tdf
tdf.Fields.Append .CreateField("Name", dbText, 50)
Set fld = .CreateField("Id", dbLong)
fld.Attributes = fld.Attributes + dbAutoIncrField
.Fields.Append fld
...and so on
 
Back
Top