Question : How to Create Field with Autonumber?

How can I in code where I do CreateField() make it an Autonumber ?

Answer : How to Create Field with Autonumber?

hi eeevbeee,

here is an example:

Private Sub cmdCreateTable_Click()
Dim dbs As DAO.Database
Dim tdf As TableDef
Dim fld As Field


 Set dbs = CurrentDb
 Set tdf = dbs.CreateTableDef("table000")
 
 Set fld = tdf.CreateField("lngID", dbLong)
 fld.Attributes = fld.Attributes + dbAutoIncrField
 tdf.Fields.Append fld
 
 dbs.TableDefs.Append tdf
 
 Set dbs = Nothing
End Sub


cheers
Ricky
Random Solutions  
 
programming4us programming4us