Link to home
Start Free TrialLog in
Avatar of garrenb
garrenbFlag for Ireland

asked on

Creating an Auto Number field in MSAccess using "DbAutoIncrField "

Hi Guys,

If I wanted to create an Autonumber field called "Id" in an MS Access table , what extra would I need to add to the code below...

Dim dbsNorthwind As Database
   Dim tdfNew As TableDef
   Dim fldLoop As Field
   Dim prpLoop As Property

   Set dbsNorthwind = OpenDatabase("Northwind.mdb")

   Set tdfNew = dbsNorthwind.CreateTableDef("NewTableDef")

   ' Create and append new Field objects for the new
   ' TableDef object.
   With tdfNew
      ' The CreateField method will set a default Size
      ' for a new Field object if one is not specified.
      .Fields.Append .CreateField("TextField", dbText)
      .Fields.Append .CreateField("IntegerField", dbInteger)
      .Fields.Append .CreateField("DateField", dbDate)
   End With

   dbsNorthwind.TableDefs.Append tdfNew

Thanx in advance,

GarrenB
ASKER CERTIFIED SOLUTION
Avatar of casassus
casassus

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of garrenb

ASKER

Hiya,

You know I must have tried almost every method of getting this to work. If I had asked this question 2 hours ago I might have some hair left.

Many thanks,


Garren
Avatar of garrenb

ASKER

Hey Cassasus,

Following on from here, is it easy to set a field's attribute to Allow Zero Length?  

50 Points on offer for u.

Thanks,

GarrenB