Help ... Creating AutoNumber Field!!! 
Author Message
 Help ... Creating AutoNumber Field!!!

As you can see by the function below it creates a new table within my
database.  What I'm really wanting to ask is if there is a way to create an
'AutoNumber' field.  The first 'CreateField' item creates the field "number"
as a Text format.  I really want to set the data type of this field to
AutoNumber but am not sure how to do this.  Can anyone help me.

Daniel Wright

    Function createTemp()

        Dim dbs As Database, tdf As TableDef, fld As Field

        Set dbs = CurrentDb

        Set tdf = dbs.CreateTableDef("tblTemp")

        Set fld = tdf.CreateField("number", dbText, 50)
        tdf.Fields.Append fld
        tdf.Fields.Refresh

        Set fld = tdf.CreateField("name", dbText, 50)
        tdf.Fields.Append fld
        tdf.Fields.Refresh

        Set fld = tdf.CreateField("medicareid", dbText, 50)
        tdf.Fields.Append fld
        tdf.Fields.Refresh

        Set fld = tdf.CreateField("effectivedate", dbDate, 6)
        tdf.Fields.Append fld
        tdf.Fields.Refresh

        Set fld = tdf.CreateField("receivedate", dbDate, 6)
        tdf.Fields.Append fld
        tdf.Fields.Refresh

        Set fld = tdf.CreateField("repinitials", dbText, 50)
        tdf.Fields.Append fld
        tdf.Fields.Refresh

        Set fld = tdf.CreateField("batchnumber", dbText, 50)
        tdf.Fields.Append fld
        tdf.Fields.Refresh

        dbs.TableDefs.Append tdf
        dbs.TableDefs.Refresh
        Set dbs = Nothing

    End Function



Mon, 24 Jul 2000 03:00:00 GMT  
 Help ... Creating AutoNumber Field!!!

daniel,

this is taken from the vb books online

"... define a field with the dbLong data type and set dbAutoIncrement in
the Field objects Attributes property."

something like this:
Set fld = tdf.CreateField("number", dbLong)
        tdf.Attributes=dbAutoIncrement
        tdf.Fields.Append fld
            tdf.Fields.Refresh
hth

/mvb



Quote:
> As you can see by the function below it creates a new table within my
> database.  What I'm really wanting to ask is if there is a way to create
an
> 'AutoNumber' field.  The first 'CreateField' item creates the field
"number"
> as a Text format.  I really want to set the data type of this field to
> AutoNumber but am not sure how to do this.  Can anyone help me.

> Daniel Wright

>     Function createTemp()

>         Dim dbs As Database, tdf As TableDef, fld As Field

>         Set dbs = CurrentDb

>         Set tdf = dbs.CreateTableDef("tblTemp")

>         Set fld = tdf.CreateField("number", dbText, 50)
>         tdf.Fields.Append fld
>         tdf.Fields.Refresh

>         Set fld = tdf.CreateField("name", dbText, 50)
>         tdf.Fields.Append fld
>         tdf.Fields.Refresh

>         Set fld = tdf.CreateField("medicareid", dbText, 50)
>         tdf.Fields.Append fld
>         tdf.Fields.Refresh

>         Set fld = tdf.CreateField("effectivedate", dbDate, 6)
>         tdf.Fields.Append fld
>         tdf.Fields.Refresh

>         Set fld = tdf.CreateField("receivedate", dbDate, 6)
>         tdf.Fields.Append fld
>         tdf.Fields.Refresh

>         Set fld = tdf.CreateField("repinitials", dbText, 50)
>         tdf.Fields.Append fld
>         tdf.Fields.Refresh

>         Set fld = tdf.CreateField("batchnumber", dbText, 50)
>         tdf.Fields.Append fld
>         tdf.Fields.Refresh

>         dbs.TableDefs.Append tdf
>         dbs.TableDefs.Refresh
>         Set dbs = Nothing

>     End Function



Mon, 24 Jul 2000 03:00:00 GMT  
 Help ... Creating AutoNumber Field!!!

Look up Attributes in the help file.

  Set fld = tdf.CreateField("number", dbLong, 50)
  fld.Attributes = dbAutoIncrField
  tdf.Fields.Append fld
  tdf.Fields.Refresh

Quote:

>As you can see by the function below it creates a new table within my
>database.  What I'm really wanting to ask is if there is a way to create an
>'AutoNumber' field.  The first 'CreateField' item creates the field
"number"
>as a Text format.  I really want to set the data type of this field to
>AutoNumber but am not sure how to do this.  Can anyone help me.

>Daniel Wright

>    Function createTemp()

>        Dim dbs As Database, tdf As TableDef, fld As Field

>        Set dbs = CurrentDb

>        Set tdf = dbs.CreateTableDef("tblTemp")

>        Set fld = tdf.CreateField("number", dbText, 50)
>        tdf.Fields.Append fld
>        tdf.Fields.Refresh

>        Set fld = tdf.CreateField("name", dbText, 50)
>        tdf.Fields.Append fld
>        tdf.Fields.Refresh

>        Set fld = tdf.CreateField("medicareid", dbText, 50)
>        tdf.Fields.Append fld
>        tdf.Fields.Refresh

>        Set fld = tdf.CreateField("effectivedate", dbDate, 6)
>        tdf.Fields.Append fld
>        tdf.Fields.Refresh

>        Set fld = tdf.CreateField("receivedate", dbDate, 6)
>        tdf.Fields.Append fld
>        tdf.Fields.Refresh

>        Set fld = tdf.CreateField("repinitials", dbText, 50)
>        tdf.Fields.Append fld
>        tdf.Fields.Refresh

>        Set fld = tdf.CreateField("batchnumber", dbText, 50)
>        tdf.Fields.Append fld
>        tdf.Fields.Refresh

>        dbs.TableDefs.Append tdf
>        dbs.TableDefs.Refresh
>        Set dbs = Nothing

>    End Function



Mon, 24 Jul 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help: How to create an autonumber field as GUID by code

2. Help on creating AutoNumber field using DBDAO

3. Please Help: Create AutoNumber field in Access DB

4. URGENT HELP NEEDED - CREATE AUTONUMBER FIELD IN VB

5. Please Help: Create AutoNumber field in Access DB

6. DAO creating an Autonumber field

7. How to create a table with Autonumber field?

8. Creating autonumber field to table

9. Can you create an autonumber field in code ?

10. Creating HyperLink and AutoNumber Fields in code

11. Create AutoNumber field in code

12. creating an autonumber field in DAO

 

 
Powered by phpBB® Forum Software