?
Solved

AutoNumber for DAO CreateField

Posted on 1998-08-18
2
Medium Priority
?
501 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 600 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

766 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