Log in

View Full Version : VBA Code for adding an autonumber primary key


cuuplate
Jun 21, 2009, 01:54 PM
Can anyone provide code for adding an autonumber field to an existing database and then making that field the primary key?

Thank you.

ScottGem
Jun 21, 2009, 02:04 PM
Can I ask Why you want to do this in VBA? Don't you have access to the tables? Since this is a one time deal, why bother?

cuuplate
Jul 1, 2009, 09:06 PM
Can I ask Why you want to do this in VBA? Don't you have access to the tables? Since this is a one time deal, why bother?

This is not a one-time deal. I have code to automatically import data from an excel spreadsheet. I want to add code to add a primary key index to this import to speed up queries based on this data. The data is imported as 18 separate tables, and it is refreshed weekly. So, I don't want to have to manually add 18 indexes every single week.