INSERT primary key with autocounter

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

INSERT primary key with autocounter

Post by sal21 »

I just have a table with many fileds.
I nedd to add a filed named AKEY a primary key with autocounter into the top of fields list.
All with code vb and jet conn or adox code. Possible?

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

Re: INSERT primary key with autocounter

Post by HansV »

Create an SQL string like this:

Dim strSQL As String
strSQL = "ALTER TABLE MyTable ADD COLUMN AKEY COUNTER CONSTRAINT PrimaryKey PRIMARY KEY"

where MyTable is the name of the table.

You can use the Execute method of your ADODB Connection object to run the SQL.
Best wishes,
Hans