Solved

Creating an Auto Number field in MSAccess using "DbAutoIncrField "

Posted on 2001-07-06
3
330 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
ID: 6259609
For instance

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


0
 
LVL 1

Author Comment

by:garrenb
ID: 6259767
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
ID: 6260084
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

840 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