Solved

AutoNumber for DAO CreateField

Posted on 1998-08-18
2
493 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
[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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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