Results 1 to 2 of 2
  1. #1
    Lounger
    Join Date
    Aug 2006
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Autonumber field in table (AccessXP)

    How do I programmatically add an autonumber field to an existing table?

    I have tried using "CreateField", but it won't allow me to create an autonumber field:

    CurrentDb.TableDefs(sTablename).Fields.Append _
    CurrentDb.TableDefs(sTablename).CreateField("ID", dbGUID)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Autonumber field in table (AccessXP)

    Do it like this:

    Dim tdf As TableDef
    Dim fld As DAO.Field

    Set tdf = CurrentDb.TableDefs("sTablename")
    Set fld = tdf.CreateField("ID", dbLong)
    fld.Attributes = dbAutoIncrField
    tdf.Fields.Append fld

    Set fld = Nothing
    Set tdf = Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •