Solved

Creating an Auto Number field in MSAccess using "DbAutoIncrField "

Posted on 2001-07-06
3
308 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:garrenb
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
casassus earned 100 total points
Comment Utility
For instance

.Fields.Append .CreateField("ID", dbLong)
.fields("ID").Attributes = dbAutoIncrField    


0
 
LVL 1

Author Comment

by:garrenb
Comment Utility
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
0
 
LVL 1

Author Comment

by:garrenb
Comment Utility
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
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now