Solved

AutoNumber for DAO CreateField

Posted on 1998-08-18
2
469 Views
Last Modified: 2008-03-04
From what I gather so far, it does not seem to be possible to create a field object (i.e. CreateField) with an AutoNumber datatype using Access VBA/DAO. Is this correct? If so, there's got to be a trick to get around it somehow, doesn't there?
My hunch is that the AutoNumber thing is part of one of those special Document objects that Access tags onto certain DAOs (i.e., custom property), and is specific only to Access, and not really supported solely at the DAO level. Am I on the right track? Completely off-base?
0
Comment
Question by:mdoleman
2 Comments
 
LVL 4

Accepted Solution

by:
tomook earned 150 total points
ID: 1959575
Try this:

Sub CreateTableWithAutonumber(TableName As String)
    Dim db As Database
    Dim td As TableDef
    Dim fd As Field
   
    Set db = CurrentDB
    Set td = CurrentDB.CreateTableDef("tblTestAutonum")
   
    Set fd = td.CreateField("fldTestAutonum")
    fd.Type = dbLong
    ' Here is the real trick. Have to set the attributes.
    fd.Attributes = dbAutoIncrField
    td.Fields.Append fd
    db.TableDefs.Append td
   
    Set fd = Nothing
    Set td = Nothing
    Set db = Nothing
End Sub

1
 

Author Comment

by:mdoleman
ID: 1959576
Thanks Tomook, that's the answer; ashamed I didn't find that one myself.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

757 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

21 Experts available now in Live!

Get 1:1 Help Now