add autonumber field to table using DAO 
Author Message
 add autonumber field to table using DAO

is it possible to add an AutoNumber field to a table, using DAO CreatField and tabledef.fields.Append fld?  I don't see a FieldType
for autonumber, or any way to set the attributes for a Long field

(david)



Sun, 02 Nov 2003 18:47:26 GMT  
 add autonumber field to table using DAO


Quote:
> is it possible to add an AutoNumber field to a table, using DAO CreatField and tabledef.fields.Append fld?  I don't see a FieldType
> for autonumber, or any way to set the attributes for a Long field

> (david)

The field type is dbLong and the attribute = dbAutoIncrField

Hope this helps

Tony Oakley



Sun, 02 Nov 2003 20:01:05 GMT  
 add autonumber field to table using DAO

How do you apply the attribute?


    is it possible to add an AutoNumber field to a table, using DAO CreatField and tabledef.fields.Append fld?  I don't see a FieldType
    for autonumber, or any way to set the attributes for a Long field
    (david)

  The field type is dbLong and the attribute = dbAutoIncrField

  Hope this helps

  Tony Oakley



Mon, 03 Nov 2003 14:48:45 GMT  
 add autonumber field to table using DAO


Quote:
> How do you apply the attribute?


>      message


>     > is it possible to add an AutoNumber field to a table,
>     > using DAO CreatField and tabledef.fields.Append fld?  I
>     > don't see a FieldType
>     > for autonumber, or any way to set the attributes for a
>     > Long field

>     > (david)

>      The field type is dbLong and the attribute = dbAutoIncrField

>      Hope this helps

>      Tony Oakley

Sub CreatePKey()

    Dim tdef As DAO.TableDef
    Dim fld As DAO.Field
    Dim idx As DAO.Index
    Dim db As DAO.Database

    Set db = CurrentDb
    Set tdef = db.TableDefs("table1")

    Set fld = tdef.CreateField("ID", dbLong)

    fld.Attributes = dbAutoIncrField
    tdef.Fields.Append fld

    'If you want to make this the primary key then
    Set idx = tdef.CreateIndex("PrimaryKey")

    With idx

        .Fields.Append .CreateField("ID")
        .Primary = True

    End With

    tdef.Indexes.Append idx

    Set fld = Nothing
    Set tdef = Nothing
    Set db = Nothing

End Sub

Hope this helps

Tony Oakley



Mon, 03 Nov 2003 15:37:33 GMT  
 add autonumber field to table using DAO

aaaaaahhhhhh ---

   I tried to set the attribute after appending the field.......

Thank you
(David L Graham)



    How do you apply the attribute?

        is it possible to add an AutoNumber field to a table, using DAO CreatField and tabledef.fields.Append fld?  I don't see a FieldType
        for autonumber, or any way to set the attributes for a Long field
        (david)

      The field type is dbLong and the attribute = dbAutoIncrField

      Hope this helps

      Tony Oakley

  Sub CreatePKey()

      Dim tdef As DAO.TableDef
      Dim fld As DAO.Field
      Dim idx As DAO.Index
      Dim db As DAO.Database

      Set db = CurrentDb
      Set tdef = db.TableDefs("table1")

      Set fld = tdef.CreateField("ID", dbLong)

      fld.Attributes = dbAutoIncrField
      tdef.Fields.Append fld

      'If you want to make this the primary key then
      Set idx = tdef.CreateIndex("PrimaryKey")

      With idx

          .Fields.Append .CreateField("ID")
          .Primary = True

      End With

      tdef.Indexes.Append idx

      Set fld = Nothing
      Set tdef = Nothing
      Set db = Nothing

  End Sub

  Hope this helps

  Tony Oakley



Tue, 04 Nov 2003 10:27:47 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Add AutoNumber field to table using code

2. Altering table to add an autonumber field

3. Adding a Autonumber field to a Make Table Query

4. Adding an AutoNumber field to a table with code

5. Add a table field with type autonumber

6. How using ADO Create a Table and Specify that a Field is autoNumber and Primary Key

7. Adding a Field to an exsisting table in DAO

8. Help on adding data after creating a table using DAO

9. Using DAO to set field properties in tables.

10. append fields to an existing table using DAO

11. Newbie Update field in DB using AutoNumber field

12. Newbie Update field in DB using AutoNumber field

 

 
Powered by phpBB® Forum Software