perhaps just posted, sorry create id key with autonumber with ado

User avatar
sal21
PlatinumLounger
Posts: 4351
Joined: 26 Apr 2010, 17:36

perhaps just posted, sorry create id key with autonumber with ado

Post by sal21 »

how create idx field in mytable with autonumber with ado?

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: perhaps just posted, sorry create id key with autonumber with ado

Post by HansV »

To add an AutoNumber field named idx in MyTable, open a connection CONN on the database, and execute the following SQL string:

Code: Select all

CONN.Execute CommandText:="ALTER TABLE MyTable ADD COLUMN idx COUNTER", Options:=adExecuteNoRecords
To create a primary index on that field, execute

Code: Select all

CONN.Execute CommandText:="CREATE INDEX PrimaryKey ON MyTable (idx) WITH PRIMARY", Options:=adExecuteNoRecords
Best wishes,
Hans