autonumber when table is created (1 Viewer)

jalverson

Registered User.
Local time
Today, 03:13
Joined
Oct 27, 2004
Messages
42
I have no experience using modules or vb with an access database, so I need some help.

I have a make table query. When the new table is created, I need to include an autonumber field. I have spent most of the morning searching this forum for a solution. One solution is to run the make query as is. After the table is created, then run code that inserts a new column field into the table which has the attributes of an autonumber field. I found this code but do not know where to paste into the database and make it run. I appreciate any responses to help solve this problem

dim db as dao.database
dim sql as string
dim stbl as string
dim sfld as string
stbl="tbl_part_number_data"
sfld ="fld_auto_id"
Set db = CurrentDb
sql = "ALTER TABLE " & stbl & " ADD COLUMN " & sfld & " AUTOINCREMENT"
db.Execute sql


Jeff
 

Johny

Registered User.
Local time
Today, 12:13
Joined
Jun 1, 2004
Messages
80
You can do this without programming:

1. Make a temporary table 'tblTemp'
2. Make a copy of 'tblTemp' and include 1 autoincrement field and name it 'tblTABLE1'
3. Make your make-table-query that makes 'tblTemp'
4. Make an append query to append all records from 'tblTemp' to 'tblTABLE1'
 

Users who are viewing this thread

Top Bottom