Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a field to Primary key once a Make Table is run

Status
Not open for further replies.

Blackshark

Programmer
May 7, 2002
48
GB
HI,

I have built a few Make Table queries to enhance the speed of various other queries and VB code.

I would like to, once the make the table is run, set a field in the newly made table to be the primary key. I can do this manually but cant find any code to do this in in VB.

Any thoughts?


Thanks Tim
 
Use the .CreateIndex method, add field(s) to the index with the .CreateField method, making sure you .Append the Field to the index, and append the index to the tabledef's .Indexes collection. the index should be created with .Unique= true, and .Primary = true.

Be sure to trap for errors--ie if there happen to be dups, you'll need to remove these (manually or in code) and retry the index creation
--jsteph
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top