Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create RandomNumber field

Status
Not open for further replies.

matrixindicator

IS-IT--Management
Sep 6, 2007
418
BE
Hoy,

You can create an autonumber field with vba. I wonder how I can set the field attributes to a Random Number. Manually you can set an autonumber field to random.

Code:
Set fld = tdf.CreateField("RNDNR", dbLong, 50)
fld.Attributes = dbAutoIncrField 'this is an increment autonumber
tdf.Fields.Append fld
 
A few notes.

Code:
    Dim db As Database
    Dim tdf As TableDef

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

    tdf.Fields.Append tdf.CreateField("RandomID", dbLong)
    tdf.Fields("RandomID").Attributes = dbAutoIncrField
    db.TableDefs.Append tdf
    tdf.Fields("RandomID").DefaultValue = "GenUniqueID()"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top