PC Review


Reply
Thread Tools Rate Thread

Creating an Autonumber field

 
 
Ed Cohen
Guest
Posts: n/a
 
      8th Jun 2008
Question - I am trying to create a field that has the datatype of AutoNumber
in code. The help page that has the datatypes does not list anything that
corresponds to the AutoNumber datatype. I need this for a table I am creating
in VBA - Access 2000. The New values property is automatically set to
Increment. Again, how do you do this in VBA? Thanks.

Ed
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      8th Jun 2008
Dim tdfCurr As DAO.TableDef
Dim fldID As DAO.Field

Set tdfCurr = CurrentDb().TableDefs("ExistingTable")
Set fldID = tdfCurr.CreateField("NewField", dbLong)
fldID.Attributes = dbAutoIncrField
tdfCurr.Fields.Append fldID

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Ed Cohen" <(E-Mail Removed)> wrote in message
news:2E57D9A4-A3EF-4CD1-972D-(E-Mail Removed)...
> Question - I am trying to create a field that has the datatype of
> AutoNumber
> in code. The help page that has the datatypes does not list anything that
> corresponds to the AutoNumber datatype. I need this for a table I am
> creating
> in VBA - Access 2000. The New values property is automatically set to
> Increment. Again, how do you do this in VBA? Thanks.
>
> Ed



 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      9th Jun 2008
See:
http://allenbrowne.com/func-DAO.html#CreateTableDAO
The example illustrates creates each field type (including autonumber.)

Note that just creating an AutoNumber does not automatically make it the
primary key. The same page also shows how to create this and other indexes:
http://allenbrowne.com/func-DAO.html#CreateIndexesDAO

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Ed Cohen" <(E-Mail Removed)> wrote in message
news:2E57D9A4-A3EF-4CD1-972D-(E-Mail Removed)...
> Question - I am trying to create a field that has the datatype of
> AutoNumber
> in code. The help page that has the datatypes does not list anything that
> corresponds to the AutoNumber datatype. I need this for a table I am
> creating
> in VBA - Access 2000. The New values property is automatically set to
> Increment. Again, how do you do this in VBA? Thanks.
>
> Ed


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Autonumber Field =?Utf-8?B?SmFtZXM=?= Microsoft Access VBA Modules 1 20th Feb 2007 07:33 PM
Creating autonumber field programmatically Amy Blankenship Microsoft Access Form Coding 2 11th Jul 2006 10:45 PM
Creating a table with an autonumber field =?Utf-8?B?TUNocmlzdA==?= Microsoft Access VBA Modules 1 22nd Jun 2005 10:19 PM
AutoNumber Field's value when creating a new record =?Utf-8?B?TGVzbGVl?= Microsoft Access Form Coding 1 22nd Apr 2004 03:35 AM
Re: Creating an 'autonumber' field in a report Cheryl Fischer Microsoft Access Reports 0 16th Sep 2003 06:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:52 AM.