how to set first field to autonumber ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello all,
i have a little question, i searched this answer base but couldn't find it
yet.
i created a new table with vba ( no sql) in access 2000.
i know how to set the field to text or number, but i want to set the first
field in the table to autonumber using vba in the same module as where i
created my table in. is this possible and if yes (then), how can it be done ?
greetings and many thanks, johan de visser
 
An AutoNumber field is a dbLong type that has its Attributes set to
dbAutoIncrField.

This kind of thing:

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

Set db = CurrentDb()
Set tdf = db.CreateTableDef("MyTable")

Set fld = tdf.CreateField("ID", dbLong)
fld.Attributes = dbAutoIncrField + dbFixedField
tdf.Fields.Append fld
 
Back
Top