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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoNumber in a MakeTable Query 1

Status
Not open for further replies.

mmck1964

Technical User
Jul 12, 2001
104
US
I have a make table query that does everthing i want except create a autonumber primary key. None of the tables I have in the query have primary keys, but I want the make table query to make on. Can this be done?
Thanks
 
Yes, this can be done but not from within the Make-Table query. You have to execute VBA code to create the additional field and the primary key. Try the following and change the names of the query, database, table, and field to your specific needs.

DoCmd.Setwarnings false
docmd.OpenQuery "qryMakeTable"
DoCmd.SetWarnings true
Dim db as DAO.Database
Set db = OpenDatabase("c:\FolderName\YourDatabase.mdb", True, False)
db.Execute "ALTER TABLE tblYourTable ADD COLUMN RecCounter AUTOINCREMENT"
db.Execute "CREATE INDEX RecCounter ON tblYourTable (RecCounter) WITH PRIMARY;"

Let me know if this works for you. I use it all of the time.
db.close Bob Scriver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top