Solved

Creating an Auto Number field in MSAccess using "DbAutoIncrField "

Posted on 2001-07-06
3
332 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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