Solved

Creating an Auto Number field in MSAccess using "DbAutoIncrField "

Posted on 2001-07-06
3
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 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